Hey all. I need to know how I can pass a URL which includes GET format variables ( url1 example: http://somesite.com/my.php?foo=stuff&bar=otherStuff ) as an argument (in GET format) to another PHP file ( url2 exampe: myfile.php?url=<url1> ).
So the final URL ends up in this sort of format:

myfile.php?[url]http://somesite.com/my.php?foo=stuff&bar=otherStuff[/url]

And of course, it doesn't work.

I've tried to replace url1 with its rawURLEncoded equivalent and then making my other file unencode the URL but it still doesn't work.

If I use POST to send the variables it works fine and dandy but in this instance I can't do that... Any help much appreciated.

    Well you could use

    _SERVER["REQUEST_URI"]

    Which will give you

    /my.php?foo=stuff&bar=otherStuff

    So you could try

    $finalURL = $_SERVER["SERVER_NAME"] .  $ _SERVER["REQUEST_URI"]; 

    Then

    myfile.php?url=$finalURL

    Give it a try

      Are those dependent on the server I'm running? I'm running Apache on this box and both those variables echo nothing unfortunately.

      I should probably clarify my purpose. Basically I'm just using PHP to access an external XML file and read it into Flash (using readfile()) because Flash wont allow access to external domains. So from Flash I send a query to read the contents of the file:
      readfile.php?theSite=http://www.somesite.com/theFile.php?foor=bar

      Any further ideas appreciated.

        Originally posted by Jesse Stratford
        I've tried to replace url1 with its rawURLEncoded equivalent and then making my other file unencode the URL but it still doesn't work.

        Well, urlencode() should work fine: the URL would be rewritten as "http%3A%2F%2Fsomesite.com%2Fmy.php%3Ffoo%3Dstuff%26bar%3DotherStuff"

        As for unencoding it, you shouldn't need to, as that's done automagically as part of the job of parsing the http request.

          Sorry fellas, I know how annoying it is when someone turns around and says the problem was actually unrelated. The urlencoding was working fine, I just had an additional set os quotes at the end 🙂 Cheers for the help!

            Write a Reply...