Maybe im missing something but im not sure. All im simply trying to do is set cookies so i can retrieve their value later. Im trying to implement such a thing but to no avail....not sure why its not working since its not that difficult.
i have a simple log in form you know, username/pass etc...nothing fancy.
On successful login, i have something like this:
//COOKIE DETAILS HERE
setcookie('username4pc',$userName);
setcookie('userpass4pc',$userPass);
header("Location:testCookie.php");
And ive made sure this is going before the HTML tag and before anything is outputted to the page. So much so that, ive taken out the above from my program that im working on and put it on a blank html page to test, and it now looks like this...
after clicking on "login" on the indexpage, it goes to my new test page which only has this:
<?php
setcookie('username4pc',$userName);
setcookie('userpass4pc',$userPass);
header("Location:testCookie.php");
?>
<html></html>
and after the above runs, the header throws it to testCookie.php
page which only has this
<?php
//test cookie
if(isset($_COOKIE['first_name'])){
echo " cookies set";
} else {
echo "cookie not set";
}
?>
<html></html>
and no matter what i do, i always get the "cookie not set"
Any ideas as to why and whats going wrong?
You're accessing the cookie wrong, it should be:
if(isset($_COOKIE['username4pc'])){
or
if(isset($_COOKIE['userpass4pc'])){
a simple var_dump($_COOKIE)
will show you exactly what's in the cookie array.