How to insert form data into a PHP cookie.?

Richard

New member
Hello. I've recently looked into PHP cookies, and I'm having a bit of trouble with making a log in with it. Here is the basic username only log in script that I have so far:
<?php
$uname=$_POST["uname"];
$pass=$_POST["pass"];
$expire=time()*60*2;
setcookie("uname", "$uname", "$expire";
echo "" .$_COOKIE["uname"]. "<br />";
print_r($_COOKIE);
?>

Now as good as that is so far, there is still a problem. (Hence this question.)
When I hit the submit button for the first time, I get directed to the page with the code above, but nothing shows. If I re-send the data from the form, the cookie is echoed successfully.
Why is it that it isn't echoing the first time I submit my username to the server? I have the form action set to 'POST', and my syntax by all means is flawless. Maybe I'm not doing the cookie right.(?) After all, I have just started re-capping on them.
 
Back
Top