Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

setcookie() not working

$
0
0
Hey guys!

I'm trying to use a simple cookie to remember my user login but after a few hours of googling and some different approaches I can't seem to get it to work. I have narrowed it down to the cookie not being set (vs not being able to GET) by using Chrome. The dev module shows the cookies of a site and I never get any to set. If anyone could point me in the right direction, that would be greatly appreciated.

Thanks!

My form that submits the data - This form does everything it's supposed to except setting the cookie. The login script and the redirects all work after this. No PHP errors
<?
if($_COOKIE['RememberUserName'] == "yes") $User = $_COOKIE['StoredUserName'];
echo "<label>User Name</label><input type = 'text' id = 'UserName' name = 'UserName' value = '$User'/>";
?>  
<div class = "clear"></div>
<label>Password</label><input type = "password" id = "Password" name = "Password"/>
<div class = "clear"></div>
<label>Remember</label>
<div class = "selectCon">
<select class = "small" id = "Remember" name = "Remember">
  <option value = "no">Off</option>
  <option value = "yes" <?if($_COOKIE['RememberUserName'] == "yes") echo 'SELECTED';?>>On</option>
</select>



Where I'm setting my cookies
$Rem = $_GET['Remember'];
if($Rem == "yes"){
  setcookie("RememberUserName", "yes", 0);
  setcookie("StoredUserName", $User, 0);
  $_COOKIE['RememberUserName'] = "yes";
  $_COOKIE['StoredUserName'] = $User;      
}else{
  setcookie("RememberUserName", "no", 0);
  setcookie("StoredUserName", "", 0);
  $_COOKIE['RememberUserName'] = "no";
  $_COOKIE['RememberUserName'] = "";      
}  



As always, thanks in advance!

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>