how to destroy session , when back is clicked

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
raj86
Forum Commoner
Posts: 25
Joined: Tue Sep 29, 2009 12:28 am

how to destroy session , when back is clicked

Post by raj86 »

Hello friends
on my home page i am having Logout hyperlink . when i click on logout it redirects me on the logout page but when i press back option in browser it goes to home page (though the session has expired).

the system should be like: When i press back option on logout page it should go on logain page instead of my home page.

Code: Select all

<?php 
session_start();
session_destroy();
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Inventry</title>

<link rel="shortcut icon" href="/inventory/scripts/animated_favicon.gif" />
<link href="/inventory/stylesheets/public.css" media="all" rel="stylesheet" type="text/css" />
<body bgcolor="#cccccc" style="color:#000099">
<div id="header">
	<h2><center>
		Inventory System
	</center></h2>
</div>
</head>
<br><br><br><br><br>
<center>Successful Logout</center><br>
<center><a href ="login.php">Click here to login again</a></center>
thank you
User avatar
iijb
Forum Commoner
Posts: 43
Joined: Wed Nov 26, 2008 11:34 pm

Re: how to destroy session , when back is clicked

Post by iijb »

Hi
Check your home page with session value in the very first line of code as.

Code: Select all

<?php
session_start();
if($_SESSION['authuser']!=1)      // or any session userid as in your code
			  {
				  echo "Sorry you dont have permission";
				  exit();
			  }
 ?>
raj86
Forum Commoner
Posts: 25
Joined: Tue Sep 29, 2009 12:28 am

Re: how to destroy session , when back is clicked

Post by raj86 »

thanks for replying
code is working.........but on logout page i am destroying the session so when i click back option, value of
$_SESSION['authuser']=0; will not go to my home page.....and it is giving
Notice: Undefined index: authuser in C:\wamp\www\inventory\index.php on line 3 on my home page when i click back option

Code: Select all

i destroy session like this in logout page
<?php 
session_start();
$_SESSION['authuser']=0;
$user=$_SESSION['user'];
session_unset();
session_destroy();
?>
Post Reply