Page 1 of 2

getting url of page you are on

Posted: Thu Aug 24, 2006 6:24 pm
by Luke
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... :?

Posted: Thu Aug 24, 2006 6:28 pm
by Jenk

Code: Select all

$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']

Posted: Thu Aug 24, 2006 6:30 pm
by Luke
thanks :oops:

Posted: Thu Aug 24, 2006 6:30 pm
by feyd
There's a user function that's been posted several times.. dig through search.php?search_keywords=geturl

Posted: Thu Aug 24, 2006 6:31 pm
by Christopher

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"];
You can also sort out the protocol scheme from $_SERVER["SERVER_PORT"].

Posted: Thu Aug 24, 2006 6:32 pm
by Luke
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. :lol:

Posted: Thu Aug 24, 2006 6:34 pm
by Luke
viewtopic.php?t=30090

(thanks feyd)

Posted: Fri Aug 25, 2006 3:50 am
by SteveB
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. :lol:
Direct from Wikipedia:
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’).”

Posted: Fri Aug 25, 2006 5:03 am
by Ollie Saunders
by describing its primary access mechanism
the protocol no?

Access mechanism and Network location are not the same, why is one being used as an example of the other?

Posted: Fri Aug 25, 2006 5:05 am
by Ollie Saunders
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();
Won't that make urls like this:

Code: Select all

http:80://www.yahoo.com
I just tried that in the browser address bar. It doesn't work

Posted: Mon Aug 28, 2006 12:07 pm
by Luke
Better solution:

The validation service can check the referer... just use this:
http://validator.w3.org/check?uri=referer

Posted: Mon Aug 28, 2006 12:51 pm
by RobertGonzalez
The CSS validator does the same thing. The only catch is it needs to be hosted on a resolvable domain (so localhost will not work).

Posted: Mon Aug 28, 2006 12:54 pm
by Luke
CSS Validator referer link doesnt' work for me. I think it has something to do with my mod_rewrite rules or something... ? :?

Posted: Mon Aug 28, 2006 12:57 pm
by RobertGonzalez
I'd be willing to bet you are not using full URI's in your CSS path, if the validator does not validate.

Posted: Mon Aug 28, 2006 1:17 pm
by Luke
:oops: