Calling URL - How?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oscardog
Forum Contributor
Posts: 245
Joined: Thu Oct 23, 2008 4:43 pm

Calling URL - How?

Post by oscardog »

Well i know its using the $_SERVER command, but i've been looking on the web and most sites just tell me its crap. I only want it for a simple job, basically if they came from logout.php , echo "You are now logged out" above the login form..

So, how do i get the URL in which they came from? Cos i obv dont want the message displayed if theycame from index.php.

Thanks!
User avatar
chopsmith
Forum Commoner
Posts: 56
Joined: Thu Nov 13, 2008 10:40 am
Location: Red Bank, NJ, USA

Re: Calling URL - How?

Post by chopsmith »

If you are just trying to find the URL of the page from which the user came, you should be able to use $_SERVER['HTTP-REFERER']. See http://us2.php.net/manual/en/reserved.v ... server.php.

However, I don't think this is what you really want to do. If you have a logout.php script, that script, once visited, should probably just unset any $_SESSION variables you have set to maintain state. Or, if you're using cookies directly, the logout.php script should just destroy those cookies.

Not sure exactly what you want to do and/or how you're doing everything else, but I think you should look into $_SESSION variables.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Calling URL - How?

Post by John Cartwright »

chopsmith wrote:If you are just trying to find the URL of the page from which the user came, you should be able to use $_SERVER['HTTP-REFERER']. See http://us2.php.net/manual/en/reserved.v ... server.php.

However, I don't think this is what you really want to do. If you have a logout.php script, that script, once visited, should probably just unset any $_SESSION variables you have set to maintain state. Or, if you're using cookies directly, the logout.php script should just destroy those cookies.

Not sure exactly what you want to do and/or how you're doing everything else, but I think you should look into $_SESSION variables.
$_SERVER['HTTP_REFERER'] should never be relied upon. It is up to the user client to send it's referal url, and is often blocked or manipulated to protect the users privacy. Instead, as chopsmith suggested, store the last visited page in a session variable.
Post Reply