Capture URL of current page
Moderator: General Moderators
-
pbritten
- Forum Newbie
- Posts: 13
- Joined: Wed Mar 24, 2004 9:24 am
- Location: State College, Pennsylvania, USA
Capture URL of current page
If it's possible, would someone be so kind as to tell me how to capture the URL of the current page and save it in a variable?
Thank you very much!
Pat
Thank you very much!
Pat
Code: Select all
<?php
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $url;
?>-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
Might try
Code: Select all
<?php
$url = getenv( "HTTP_REFERER" );
echo $url;
?>REFERER is the page that sent a user to the current page. And this is one not recommended to work with because it can be easily spoofed.reverend_ink wrote:Might tryCode: Select all
<?php $url = getenv( "HTTP_REFERER" ); echo $url; ?>
-
reverend_ink
- Forum Contributor
- Posts: 151
- Joined: Sun Apr 20, 2003 1:18 am
- Location: Las Vegas | London
-
pbritten
- Forum Newbie
- Posts: 13
- Joined: Wed Mar 24, 2004 9:24 am
- Location: State College, Pennsylvania, USA
I tried this, but only was able to capture the domain name, not the folder and filename. Any suggestions?Goowe wrote:I think this works every time... might not though... don't shoot me if it doesn'tCode: Select all
<?php $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; echo $url; ?>
try
Code: Select all
$complete_path = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
-
aleigh
- Forum Commoner
- Posts: 26
- Joined: Thu Mar 25, 2004 11:06 am
- Location: Midwestern United States
- Contact:
HTTP_HOST is not always present, sadly, but this works well enough. That variable is slaved to the HTTP "Host:" field which very old browsers and strange clients (Like OSX's "ftp"'s http support) don't always implement.
PHP does not have a clear concept of the IP that the people contacted to start the request. On my server I have been tempted to pass it into PHP into a new variable but haven't done any work on this.
You could also get the local endpoint of the socket your request is serving on but this is definitly not worth your time.
PHP does not have a clear concept of the IP that the people contacted to start the request. On my server I have been tempted to pass it into PHP into a new variable but haven't done any work on this.
You could also get the local endpoint of the socket your request is serving on but this is definitly not worth your time.
or:
Code: Select all
<?php
$complete_path = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].$_SERVER['REQUEST_URI'];
?>