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 :/ Quote Link to comment Share on other sites More sharing options...
ignace Posted May 22, 2010 Share Posted May 22, 2010 $_GET['num'] Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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); Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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']; ?> Quote Link to comment 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; Quote Link to comment 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. Quote Link to comment 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..). Quote Link to comment 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 Quote Link to comment 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); Quote Link to comment 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. Quote Link to comment 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); Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Graxeon Posted May 24, 2010 Author Share Posted May 24, 2010 page 2...bump Quote Link to comment 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.