Jump to content

Session variables


am_25

Recommended Posts

Hi,

I'm trying to use sessions for the login application.

 

I first set the session varibables and then depending on the session i enable the other pages(like search,db entry etc). After I logout, if i put the URL of the other pages in the same browser session which need user access, it shows up as if user is logged in. But it works well if I do it in a new browser.

How can I implement- after logout the user should not be able to access the pages in the same browser.

a small snippet of my loginscript.php

 

$sql="SELECT * FROM users WHERE username='$myusername' and password='$encrypted_mypassword'";
$result=mysql_query($sql);

$q = mysql_fetch_object($result);
    if(!$q) die("Login Failure: An error occured, please verify your username and password are correct.");

//set session variables 
$_SESSION['loggedin']=1;
$_SESSION['user'] =$_POST['username']; 
$_SESSION['pass'] = $_POST['password'];
header("Location:employee.php");

 

small snippet of other pages where I check for session

if (!isset($_SESSION['user'])) { 
// check if authentication was performed 
// else die with error 
die ("ERROR: Unauthorized access!"); 
} 
else
{
include "connect.php"; //connection string
print "<br><p align = 'center'>  Employee Details </p>";
print "<table align = 'center' border=1px>";
print "<tr align = 'center' class='headline'><td>Search Employee Details</td></tr>";
print "<tr ><td>";
.....

 

a small snippet of my logout.php

 

<? 
session_start();
//remove all the variables in the session 
unset($_SESSION); 

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}
// Finally, destroy the session.
session_destroy();

?>

 

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.