getting url of page you are on
Moderator: General Moderators
getting url of page you are on
What is the best way to get the url of the current page? I need to do a Validate this page's XHTML link and for some reason I can't remember how to get the current page's url... 
Code: Select all
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
There's a user function that's been posted several times.. dig through search.php?search_keywords=geturl
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Code: Select all
$full_url = 'http://' . $_SERVER["SERVER_NAME"] . $_SERVER["SCRIPT_NAME"] . '?' . $_SERVER["QUERY_STRING"];
// or
$full_url = 'http://' . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];(#10850)
Direct from Wikipedia:The Ninja Space Goat wrote:wait a minute... wouldn't it be the uri? uri is the address and url is the actual box you type it into right?
Funny how noobish I am at somethings.
A Uniform Resource Locator (URL) is a Uniform Resource Identifier which, “in addition to identifying a resource, [provides] a means of locating the resource by describing its primary access mechanism (e.g., its network ‘location’).”
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Won't that make urls like this:timvw wrote:this is the function i found here (or somewhere else)Code: Select all
function geturl() { $ports = array('https' => 443, 'http' => 80); $prefix = empty($_SERVER['HTTPS']) ? 'http' : 'https'; $url = $prefix; $url .= $_SERVER['SERVER_PORT'] != $ports[$prefix] ? ':' . $_SERVER['SERVER_PORT'] : ''; $url .= '://'; $url .= $_SERVER['HTTP_HOST']; $url .= $_SERVER['REQUEST_URI']; return $url; } echo geturl();
Code: Select all
http:80://www.yahoo.comBetter solution:
The validation service can check the referer... just use this:
http://validator.w3.org/check?uri=referer
The validation service can check the referer... just use this:
http://validator.w3.org/check?uri=referer
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA