Sign in to follow this  

I'm going crazies from cookies

This topic is 2486 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Please help me before I kill someone.

I am setting a cookie value to 0 from 1, in one page. then I redirect that page to index.html. Afterwards I check the cookie value its still 1, meaning the user is still logged in? Why oh Why didn't the cookie change ?
Some code :

This is the function to logout,
[code]

function logout(){
$_COOKIE[ACTIVE_SESSION] = 0;
}[/code]

when the user clicks on a link to logout, that link is a php file that calls this function. as of right now cookie[active_session] is 0. Its either 1 or 0. 1 = logged in, 0 = logged out.

Now php file redirects the location to index.html using meta refresh.

From index.html, I click a link that shows info about the user if he is logged in, here is the php code :
[code]

<?php
include("utility.php");

if(isLoggedIn()){
echo "<h1> Welcome '" . getUserName() . "' enjoy the scenery</h1>";
}
else{ //invalid user
echo "<h1>Sorry you are not registered...please wait for redirection</h1>";
redirectToHomePage(3);
}
?>
[/code]

as you see isLoggedIn gets called first, remind you that cookie[active_session] should still be 0.

Now isLoggedIn() is this :
[code]

function isLoggedIn(){
if(isset($_COOKIE[ACTIVE_SESSION])){
return ( $_COOKIE[ACTIVE_SESSION] == 1) ;
}
else return false;
}
[/code]

now the problem is that this function returned 1? WTF??

Please help me.

Share this post


Link to post
Share on other sites
To set a cookie, use [url=http://php.net/setcookie]setcookie()[/url] - writing to the [i]$_COOKIE[/i] superglobal does not automatically send the cookie back to the user's browser.

Share this post


Link to post
Share on other sites

This topic is 2486 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this