Im trying to get a php form to either autopopulate a user ID field from a cookie or if it is a new pc then give the user the option of ‘remember me’. when I manually add a cookie and then load the form page it populates the user box correctly, but I cant seem to set a cookie when it is posted from the form itself.
Code from the php form:
<form action="./post_cookies.php" method="post" id="HOME">
<div id="nav">
<ul>
<li><i>Whats your username:</i></li>
<li><i><input type="text" size="40" name="User_ID"
<?php
if (isset($_COOKIE["user"]))
echo "value=\"" . $_COOKIE["user"] . "\"</i></li>";
else
echo "placeholder=\"12345\"></i></li>";
?>
<li><i>Remember me: <INPUT TYPE="checkbox" NAME="remember" VALUE="1"> Yes</i></li>
</ul>
</div>
<div id="nav" style="text-align:center;">
<ul>
<li><i><button form="HOME" type=submit style="width:200px;height:40px">Submit</button></i></li>
</form>
</ul>
</div>
</div>
this form posts to ‘post_cookies.php’ the code is:
<?php
// creating a variable to store the timestamp in
$posttime = time();
// if the remember me checkbox returns a 1 then add the users, username as a cookie
if($_POST[remember]==1)
{
setcookie('user', $_POST[User_ID], $posttime + 3600); // Sets the cookie
}
// this is where the data base connection would go
header("Location: http://www.domain.com/index.php");
?>
The idea is that if the ‘remember me’ is checked then the post_cookies.php will set a cookie with the usersID.
I cant see where post_cookies.php is going wrong and not setting a cookie.
any assistance is greatly appreciated.
thanks!
Mathew
It should be:
The array key is in quotes. Try that
Same with
Also
Is missing a closing
>before the</i>