Page 1 of 1

session_destroy

Posted: Thu Jan 20, 2011 1:30 pm
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???

Re: session_destroy

Posted: Thu Jan 20, 2011 1:33 pm
by Jonah Bron
We would need to see the code in login.php

Re: session_destroy

Posted: Thu Jan 20, 2011 1:52 pm
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;