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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.