Graxeon Posted May 22, 2010 Share Posted May 22, 2010 I have this URL: site.com/url/1234 That URL redirects to: site.com/image.php?num=25&loc=china How can I get "num" after I am redirected? I feel so dumb for not understanding this :/ Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/ Share on other sites More sharing options...
ignace Posted May 22, 2010 Share Posted May 22, 2010 $_GET['num'] Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062004 Share on other sites More sharing options...
Graxeon Posted May 22, 2010 Author Share Posted May 22, 2010 But I have to load the URL first. Edit: As in: loadpage(site.com/url/1234) $_GET['num'] //from the page Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062007 Share on other sites More sharing options...
Graxeon Posted May 22, 2010 Author Share Posted May 22, 2010 I'll rephrase my question I'm on a page called "home.php" "home.php" has code in it that does this: 1. Opens "site.com/url/1234" 2. That URL redirects to "site.com/image.php?num=25&loc=china" 3. "home.php" now gets the value of "num" from that new URL and echos it. So the end product after opening "home.php" is: 25 How can I do this? I know $_GET but that's for what's already in the browser bar. How can I "get" the "num" after I open "site.com/url/1234" It doesn't matter what the contents of "site.com/url/1234" and "site.com/image.php?num=25&loc=china" are. I'm only working with the URLs themselves. Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062010 Share on other sites More sharing options...
ignace Posted May 22, 2010 Share Posted May 22, 2010 $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_exec(); $url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); $query = parse_url($url, PHP_URL_QUERY); Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062011 Share on other sites More sharing options...
Graxeon Posted May 22, 2010 Author Share Posted May 22, 2010 Sorry...could you explain that to me? I don't know how that works or how to apply the URLs. Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062012 Share on other sites More sharing options...
Graxeon Posted May 22, 2010 Author Share Posted May 22, 2010 I read the PHP cURL manual but I'm still lost on this. I also tried googling different things about curl and $_get but I couldn't find anything that explained it clearly. Help please? Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062027 Share on other sites More sharing options...
Graxeon Posted May 23, 2010 Author Share Posted May 23, 2010 any ideas or help with Ignace's code? Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062099 Share on other sites More sharing options...
Tonic-_- Posted May 23, 2010 Share Posted May 23, 2010 cURL executes a external script. The code he wrote is what you are looking for. Execute the site url and get the variables in the GET session. Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062101 Share on other sites More sharing options...
Graxeon Posted May 23, 2010 Author Share Posted May 23, 2010 Ok, but I keep getting this error code: Wrong parameter count for curl_exec() And is this how I setup the script? Again, I don't know exactly how this code works. <?php $url = "site.com/url/1234"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_exec(); $url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); $query = parse_url($url, PHP_URL_QUERY);; echo $_GET['file']; ?> Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062104 Share on other sites More sharing options...
Tonic-_- Posted May 23, 2010 Share Posted May 23, 2010 eh, he started curl_exec try this $url = "site.com/url/1234"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); $url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); $query = parse_url($url, PHP_URL_QUERY);; echo $query; Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062106 Share on other sites More sharing options...
Graxeon Posted May 23, 2010 Author Share Posted May 23, 2010 It didn't display anything. It got rid of the error, though. Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062110 Share on other sites More sharing options...
Tonic-_- Posted May 23, 2010 Share Posted May 23, 2010 Ahh, not to formiliar with the CURLINFO_EFFECTIVE_URL setup but I ran a test script and got what I needed from a redirecting url. But anyways the $query contains the current url session web address and phrases it for the get variables. The curl_exec was executing the entire page and making it display the data to me, (not something you want..). Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062112 Share on other sites More sharing options...
Graxeon Posted May 23, 2010 Author Share Posted May 23, 2010 so am I supposed to take out the $query? Sorry, I'm not familiar with it either lol Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062178 Share on other sites More sharing options...
ignace Posted May 23, 2010 Share Posted May 23, 2010 The curl_exec was executing the entire page and making it display the data to me, (not something you want..). curl_setopt($curl, CURLOPT_RETURNTRANSFER, FALSE); curl_exec($curl); Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062224 Share on other sites More sharing options...
Graxeon Posted May 23, 2010 Author Share Posted May 23, 2010 So like this? <?php $url = "site.com/url/1234"; $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, FALSE); curl_exec($curl); $url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); $query = parse_url($url, PHP_URL_QUERY); echo $query; ?> If it is...it's not showing anything. I get a blank page. Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062240 Share on other sites More sharing options...
ignace Posted May 23, 2010 Share Posted May 23, 2010 $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); Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062275 Share on other sites More sharing options...
Graxeon Posted May 23, 2010 Author Share Posted May 23, 2010 Sorry...last request: can you tell me where I include the "site.com/url/1234" URL? Because I tried this but it didn't return anything: $url = "site.com/url/1234"; $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); echo $query; This code is not in "site.com/url/1234" ...it's in a different PHP file (let's call it "home.php") so it has to have some refference to "site.com/url/1234" within that PHP file. Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062283 Share on other sites More sharing options...
Graxeon Posted May 24, 2010 Author Share Posted May 24, 2010 page 2...bump Link to comment https://forums.phpfreaks.com/topic/202597-get-part-of-url/#findComment-1062435 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.