Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting Cookies

Status
Not open for further replies.

estrellas

Programmer
Jul 16, 2004
48
US
Why Cookies?
I'm using them for controlled access to certain pages. Here's how I create it:
Code:
if($_POST['Submit']){

	//assign a variable to the username the user input
	$username = $_POST['user'];

	//assign a password to the username the user input
	$password = $_POST['pass'];

	if ($username=="coolThing" && $password=="coolPass){
		// If username and password is right , store the session in a cookie
		setcookie ('logedin', '1',time()+30000); // Set the length of the cookie to 30000
		
		//Create the Session id's (as many as you want, can also do the same with cookied)
		$_SESSION['logedin'] = "1";
		$_COOKIE['logedin'] = "1";
		
}
}
?>
This works wonderfully.

The Problem?
LOGGING OUT.
Here's what I have right now and it doesn't seem to be working so well.
Code:
<?

// If the form was submited Log Off The User
if($_POST['logoff']){

// Delete the cookie
setcookie ('logedin','');
// Set its time to minus 300 (more secure)
setcookie ('logedin' , '',time()-300);
// End All Session ID'S
$_SESSION = array();
// KILL ALL SESSIONS
session_destroy();
//Rdirect User our
//Redirect user out
header("Location: login.php");
exit();
}

?>
do you guys have any clues why this is not deleting my cookie that is holding all of the login information?

here's the errors i'm getting by the way: (all 4 appear)

Warning: Cannot modify header information - headers already sent by ...

Warning: Cannot modify header information - headers already sent by ...

Warning: session_destroy(): Trying to destroy uninitialized session in ...

Warning: Cannot modify header information - headers already sent by ...

Thanks again and cheerio :)

-------
 
For the first, second, and fourth errors, see section 1.4 of my FAQ "Debugging PHP code": faq434-2999

The third error is probably related to the same problem.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top