"Stijn Goris" <me*****@hotmai l.com> wrote in message
news:3f******** *************** @reader1.news.s kynet.be...
hi all,
Trying to get those cookies to work but they wont...
Doing this. Have a page login.php wich tests the user and pass. If they
are correct a cookie is set with one variable like this: setcookie
("cookieUser ", $user);
then the browser is sent with header("Locatio n: spelersPage.php "); to
another page.
I there try to read the cookievariable cookieUser on the spelersPage.php
like this.
<?
$test = $_COOKIE["cookieGebruike r"];
echo "|$test";
?>
without any succes. Someone has an idea. The page is im my Thrusted sites
list...
kind regards
Stijn
Your problem is likely due to a limitation to cookies, not php.
A refresh has to have occured before your cookie becomes available to your
environment thus if you were to refresh your browser a couple of times you
should get your cookie. If not, as a test, I tend to use phpinfo(); alot
when doing various tests on form and cookie variables... Try writing the
following few lines to a php script file of its own (call it cookieTest.php
for our example).
<?
// For our test, our cookie will be the words "hello world" followed by the
eleven digit timestamp generated by time();
$ourCookie="hel lo world" . time();
setcookie("ourT estCookie", $ourCookie);
print("<br>1 = The cookie we just set is $ourCookie<br>" );
print("<br>2 = However the cookie that is already baked is:
$_COOKIE[ourTestCookie]");
phpinfo();
?>
View this code in a page of its own... refresh the page a few times and
examine the values that are output - and while you're at it, examine the
output of phpinfo();.
I would expect that you should find something like
1 = The cookie we just set is hello world1234567890 1
2= However the cookie that is already baked is:
The next time your refresh your browser, you should find the output
something like the following
1 = The cookie we just set is hello world1234567891 1
2= However the cookie that is already baked is:hello world1234567890 1
Note that the cookie the first time was sent to the browser but could not be
read yet (until you re-freshed the browser).