Re: Current URL?
| From: | Matthew Weier O'Phinney | Date: | Fri, 12 Nov 2004 14:12:03 +0000 |
| Subject: | Re: Current URL? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-201843@lists.php.net to get a copy of this message | ||
* Jason Paschal <jpaschal@gmail.com>:
> Trying to get the current viewed page's URL (query string intact).
>
> this works, but infrequently:
>
> $url = $_SERVER['URI'];
>
> and this ignores the query string:
>
> $url = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
>
> I'm certain there's a way, that is browser-independent, to get your
> script to grab the current URL (even if the script is an include).
>
> i'm just trying to get a log of users currently online, and which page
> they are viewing, and while the $_SERVER['REMOTE_ADDR'] will
> invariably grab the IP, $_SERVER['URI'] is often empty.
Try:
$url = $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'];
--
Matthew Weier O'Phinney | mailto:matthew@garden.org
Webmaster and IT Specialist | http://www.garden.org
National Gardening Association | http://www.kidsgardening.com
802-863-5251 x156 | http://nationalgardenmonth.org