session_destroy

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
shashanksingh
Forum Newbie
Posts: 1
Joined: Thu Jan 20, 2011 1:25 pm

session_destroy

Post by shashanksingh »

I used the above code in my index.php

Code: Select all

<?php
session_start();

if(!isset($_SESSION['login']))
{
	header("Location: login.php");
}

//rest code
?>
and I have another file logout.php

Code: Select all

<?php
	session_unset();
	
	session_destroy();
	
	header("Location:login.php");
?>
but even after loggin out I can still access index.php. Why???
Last edited by Benjamin on Thu Jan 20, 2011 2:08 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: session_destroy

Post by Jonah Bron »

We would need to see the code in login.php
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: session_destroy

Post by AbraCadaver »

You need to start the session so it knows what session to destroy/unset:

Code: Select all

session_start();
session_unset();
session_destroy();
header("Location:login.php"); //really should be an absolute URL
exit;
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply