redirect info

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
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

redirect info

Post by sebs »

is there a function or a way to find out the page that opened the curent page.I mean if code.php sends you to search.php,in search.php how can I find out that code.php send me here?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

You can use the $_SERVER['HTTP_REFERER'] but it is bullet proof.
sebs
Forum Commoner
Posts: 97
Joined: Tue Sep 20, 2005 10:13 am

Post by sebs »

As it writes in the documentation:'HTTP_REFERER'
"it cannot really be trusted".Is there any other way?
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

If you created the referring page, you can use session files and session file check on the receiving page.

Code: Select all

<?php
session_start();

$_SESSION['REFERER'] = $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];

header('Location: receiver.php');

?>
And on the receiving page:

Code: Select all

<?php
session_start();

if ($_SESSION['REFERER'] == 'http://www.yourdomain.com/sending.php') {
  //woo!
} else {
  //boo!
}
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

When people are online on a site of mine, I track their movements by sessionid stored in a database.
Seems like a slack job having to set manually the pages they are on throughout each page..
Post Reply