Question

I'm writing a "pipe" of sorts to rename and drop parts of an iCal feed. And I want the script to take different feed URL's as input.

It's source parameter value contains parameter separators and the parameters look like this:

?source=https://web.timeedit.se/hig_no/db1/timeedit/p/open/r.ics?sid=3&p=20130819.x%2C20131130.x&objects=160812.183&ox=0&types=0&fe=0&pp=f

Here's an excerpt of my code:

<?php $params = $_GET;
$content = file_get_contents($params['source']);
// ...

But this will not work since the print_r of $_GET looks like this:

Array
(
    [source] => http://www.example.com/?source=https://web.timeedit.se/hig_no/db1/timeedit/p/open/r.ics?sid=3
    [p] => 20130819.x,20131130.x
    [objects] => 160812.183
    [ox] => 0
    [types] => 0
    [fe] => 0
    [pp] => f
)

How can I get the full URL and not just the [source] value? Alternatively, is there a better way to retrieve the URL? Preferrably one where I can just paste the URL into the parameters.

Was it helpful?

Solution

Using $_SERVER.

   function saveUrl() {

       $pageURL = $_SERVER["REQUEST_URI"]; 

       $URL=urlencode($pageURL);

       return $URL;
   }
      $URL_ENC=saveUrl();

OTHER TIPS

you must urlencode the source for example

source=https%3A%2F%2Fweb.timeedit.se%2Fhig_no%2Fdb1%2Ftimeedit%2Fp%2Fopen%2Fr.ics%3Fsid%3D3%26p%3D20130819.x%2C20131130.x%26objects%3D160812.183%26ox%3D0%26types%3D0%26fe%3D0%26pp%3Df%0A

now you will get full url in encoded format.

then use it like below.

$url = urldecode($_GET['source']);

this will have your full url

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top