Hi,
I am trying to set a cookie equal to the value of a username text box on a login form.
Once the user logs in they have access to a bunch of admin pages. On the top of these admin pages i would like to simply display a welcome message which will display whatever value the cookie is set to.
For example if Eric logs in the welcome message will say "Welcome Eric."
Here is the code that i have:
Login Page:
<form action="page1.php" method=post>
username: <input name="txt_username" type="text" value="">
password: <input type="password" name="txt_password">
<input type= submit value="Submit" name="Submit">
</form>
Here is the php code i have on "page1.php"
<?php
setcookie("user", $_POST["txt_username"], time()+3600);
?>
<?php
if (isset($_COOKIE["user"]))
echo "Welcome " . $_COOKIE["user"] . "!<br />";
?>
When i first login nothing appears, but when i refresh the page it does display the cookie. Do i need to set the cookie on the previous page?
Thanks,
I am trying to set a cookie equal to the value of a username text box on a login form.
Once the user logs in they have access to a bunch of admin pages. On the top of these admin pages i would like to simply display a welcome message which will display whatever value the cookie is set to.
For example if Eric logs in the welcome message will say "Welcome Eric."
Here is the code that i have:
Login Page:
<form action="page1.php" method=post>
username: <input name="txt_username" type="text" value="">
password: <input type="password" name="txt_password">
<input type= submit value="Submit" name="Submit">
</form>
Here is the php code i have on "page1.php"
<?php
setcookie("user", $_POST["txt_username"], time()+3600);
?>
<?php
if (isset($_COOKIE["user"]))
echo "Welcome " . $_COOKIE["user"] . "!<br />";
?>
When i first login nothing appears, but when i refresh the page it does display the cookie. Do i need to set the cookie on the previous page?
Thanks,