Jump to content

Redirect by HTTP_REFERER


Alexhoward
 Share

Recommended Posts

Hi Guys,

 

wondering if anyone could help me out with this...?

 

I have a member area (amongst others) that require login to access.

 

thing is if you are not logged in it bounces you back to the login page

 

when the user logs in i would then like to take them back to where they were trying to get to

 

i'm using the header function but can't seem to get it to work with $_SERVER['HTTP_REFERER']

 

could anyone tell me if this is possible and if so how?

 

Thanks in advance!

 

Add Some Music

http://www.addsomemusic.co.uk

 

 

Link to comment
Share on other sites

store the value into session first:

<?php
  session_start();
  if(!$_SESSION['username']){ //Not logged in
    $_SESSION['last_page'] = $_SERVER['REQUEST_URI'];
    header('Location: login.php');
    exit;
  }
?>

 

<?php
  session_start();
  if($_POST['user']){
    //Validate user here

    $page = $_SESSION['last_page'] ? $_SESSION['last_page'] : 'home.php';
    unset($_SESSION['last_page']);
    header('Location: '.$page);
    exit;
  }
?>

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

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