Jump to content

header() redirect and $_SERVER['HTTP_REFERER'] Question...


whit3fir3

Recommended Posts

Is there a way to get the last page a user visited if you redirect them with a header('Location: ');  I am trying to make it so that if a user visits a page and is not loged it, they automatically get redirected to a login page then after they login they are sent back to the page they last tried to access.  The only problem is after I redirect $_SERVER['HTTP_REFERER'] comes up null.  Any ideas?

 

Thanks,

 

whit3fir3

Use sessions. When they enter a page store that page in a session variable, then use it to send them back there:

Page 1:

<?php
session_start();
$_SESSION['return_to'] = $_SERVER['PHP_SELF'];
?>

 

Login Page:

<?php
session_start();
//
//  login code 
//
if (isset($_SESSION['return_to'])) {
   header('location: ' . $_SESSION['return_to']);
   exit();
}
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.