Jump to content

Using a session variable to remember a page?


Solarpitch

Recommended Posts

Hey Guys,

Just wondering if I can use a session variable to remember what page the user was at last. ie. If user tries to login, it will bring them to process_login.php. If the login failed, the user selects "go back" and it will load the page that the user tired to login at.

Cheers.
Yes you can, you just need to do something like this on the top of every page (after session_start()).

[code]<?php
$_SESSION['last_page'] = (!isset($_SESSION['curr_page'])) ? "index.php" : $_SESSION['curr_page'];
$_SESSION['curr_page'] = $_SERVER['PHP_SELF'];
?>[/code]

Then you can use the header() function to redirect using $_SESSION['last_page'].

Orio.

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.