Jump to content

Ajax Cookie Doen't Stick.


MrFish
 Share

Recommended Posts

I'm using ajax to check if a username/password match exists for the username/password typed in. The problem is, it won't stick. When you login, if it is successful, this code runs and the div that holds the forms takes on the echo value. And it works correctly. But when you refresh the cookie no longer exists. Why is this? Is there a problem with my $time?

$time = time()+60*60*24*365;setcookie("username", $username, $time);echo "You're logged in, <b>" . $_COOKIE["username"] . "</b>.";

Link to comment
Share on other sites

No, there's not a problem with the time. After you run the code and set the cookie check in the browser's list of cookies to see if it was actually created.Additionally, cookies are not a good way to keep track of who is logged in, at least not without some sort of encryption or protection. It's easy enough to make any cookie you want, so I can create a cookie for your domain called "username" with the name "admin" and, if you don't take any other precautions, you'll assume I'm logged in as admin.

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...