Graxeon Posted May 24, 2010 Share Posted May 24, 2010 I'm trying to make a script that will do this: 1. Go to the URL "site.com/1234" **That URL redirects me to "site.com/image.php?num=25&loc=china" 2. Retrieves what comes after ".php?num=" and echos it to the user. In this case, it would echo "25" I don't know if it's possible with $_GET because that would mean that the "num=25" was actually sent to the script, not the other way around. I think it's possible with cURL and I have this code that someone else wrote but I don't know how to use it or what it does exactly. $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_RETURN_TRANSFER, FALSE); curl_exec($curl); $url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); $query = parse_url($url, PHP_URL_QUERY); Help please? (note: I made a new topic because my first one seemed to scare people away with all of the replies, lol) Quote Link to comment https://forums.phpfreaks.com/topic/202770-retrieve-part-of-url/ Share on other sites More sharing options...
Bladescope Posted May 24, 2010 Share Posted May 24, 2010 I don't know if it's possible with $_GET because that would mean that the "num=25" was actually sent to the script, not the other way around. Try it. e.g header('Location: http://site.com/image.php?num=25&loc=china'); on that page, simply call the values using $_GET Quote Link to comment https://forums.phpfreaks.com/topic/202770-retrieve-part-of-url/#findComment-1062729 Share on other sites More sharing options...
Graxeon Posted May 24, 2010 Author Share Posted May 24, 2010 I can't change the coding of "http://site.com/image.php?num=25&loc=china" And..."site.com/1234" links to different "num" values if "site.com/1234" is changed to say..."site.com/4321". That's why I need a way of retrieving the "num" from any URL that I put in. Edit: so the script would be something like this: site.com/script.php?url=site.com/1234 -"Execute 'site.com/1234'" ***..."redirects to site.com/image.php?num25&loc=china" -"echo $_GET['num'] from site.com/image.php?num=25&loc=china" Quote Link to comment https://forums.phpfreaks.com/topic/202770-retrieve-part-of-url/#findComment-1062751 Share on other sites More sharing options...
premiso Posted May 24, 2010 Share Posted May 24, 2010 I am not sure if this is relevant or not, but if site.com/1234 redirects, you may need this in the setopt: CURLOPT_FOLLOWLOCATION For it to follow the location, then at the final location you should be able to pull the get data. I have never tried it, and I could be mistaken, but yea. Quote Link to comment https://forums.phpfreaks.com/topic/202770-retrieve-part-of-url/#findComment-1062785 Share on other sites More sharing options...
Graxeon Posted May 24, 2010 Author Share Posted May 24, 2010 Ok, but the problem is that I don't know how to connect that cURL script with the "site.com/1234" URL...if that script really does work. Quote Link to comment https://forums.phpfreaks.com/topic/202770-retrieve-part-of-url/#findComment-1062789 Share on other sites More sharing options...
Graxeon Posted May 25, 2010 Author Share Posted May 25, 2010 Would this even be possible, by the way? Quote Link to comment https://forums.phpfreaks.com/topic/202770-retrieve-part-of-url/#findComment-1062855 Share on other sites More sharing options...
Graxeon Posted May 25, 2010 Author Share Posted May 25, 2010 Page 2... Help anyone? Quote Link to comment https://forums.phpfreaks.com/topic/202770-retrieve-part-of-url/#findComment-1063210 Share on other sites More sharing options...
Graxeon Posted May 26, 2010 Author Share Posted May 26, 2010 last bump... Does ANYONE know how to do this? I didn't know it would be this difficult Quote Link to comment https://forums.phpfreaks.com/topic/202770-retrieve-part-of-url/#findComment-1063363 Share on other sites More sharing options...
salathe Posted May 26, 2010 Share Posted May 26, 2010 If you want to do this using cURL: you can make a request to the URL (e.g. site.com/1234; be sure to use appropriate cURL options, like follow location) then use curl_getinfo with CURLINFO_EFFECTIVE_URL (aside: curl_getinfo returns lots of useful information) to get the URL that the remote page redirected to. Then, to access the part(s) of the URL that you need, you can use parse_url and parse_str. P.S. The only thing difficult is working out what you really want from the descriptions given. Quote Link to comment https://forums.phpfreaks.com/topic/202770-retrieve-part-of-url/#findComment-1063431 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.