Jump to content

Cookie not being set.


pankirk

Recommended Posts

I wrote this login code and I'm using cookies instead of session. Basically my problem is that when the users login is correct it sets the cookie but doesnt redirect until I login a second time.

 

			{//grab user id from database;
			while($getId = $checkLogin->fetch_assoc())
			{
				$cookieId = $getId['id'];
			}
			setcookie("username", $cookieId, time()+3600);


			if(isset($_COOKIE['username']))
			{//redirect
				if($redirect != "none")
				{
					redirect($redirect);
				}
				else if($redirect == "none")
				{
					redirect("user.php?action=home");
				}
			}
			else if(!isset($_COOKIE['username']))
			{
				PullBox("main", "red", "Failed to register correctly.");
			}
		}

 

Thats the part of the code that I wrote for the login. You can see that I set the cookie after pulling the users ID out of the database but apparently it's not getting set because it goes straight to the "if(!isset($_COOKIE['username']))" where I need it to be set to "if(isset($_COOKIE['username']))" in order for the users to be redirected to the home page. Thanks in advance!

Link to comment
https://forums.phpfreaks.com/topic/172313-cookie-not-being-set/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.