Jump to content

Redirect by HTTP_REFERER


Alexhoward

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
https://forums.phpfreaks.com/topic/149544-redirect-by-http_referer/
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;
  }
?>

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.