Jump to content

GET part of URL?


Graxeon

Recommended Posts

I'll rephrase my question :P

 

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.