ASAAKI
05-23-2003, 06:36 PM
i've searched around as well as checked on php.net... i still don't think i've got it with cookies.
i've got a page '1.php', that has a form with a userId textbox. Users insert their id in 1.php, and submit the form. then 2.php comes up and they can see their id. when they go back to 1.php and refresh it, their id's still there. that's fine. it means the cookie did kind of work.
but if they go around somewhere else or close the window or something, and then come back, the cookied id's gone again.
:confused:
here's my code for 1.php:
<?php
if($_COOKIE['id']){
$cookieId=$_COOKIE['id'];
}
?>
.
.//do other stuff...
.
<?php
echo("<input type='text' class='txt' name='userid' value='{$cookieId}' onfocus=\"this.value=='ID' ? this.value=='' : null;\" />");
?>
and on 2.php is where the cookie is actually set:
<?php
if($_GET){
setcookie("id",$_GET['userid'],time()+60*60*24*30);
}
echo("Welcome, {$_COOKIE['id']}!");
?>
i've got a page '1.php', that has a form with a userId textbox. Users insert their id in 1.php, and submit the form. then 2.php comes up and they can see their id. when they go back to 1.php and refresh it, their id's still there. that's fine. it means the cookie did kind of work.
but if they go around somewhere else or close the window or something, and then come back, the cookied id's gone again.
:confused:
here's my code for 1.php:
<?php
if($_COOKIE['id']){
$cookieId=$_COOKIE['id'];
}
?>
.
.//do other stuff...
.
<?php
echo("<input type='text' class='txt' name='userid' value='{$cookieId}' onfocus=\"this.value=='ID' ? this.value=='' : null;\" />");
?>
and on 2.php is where the cookie is actually set:
<?php
if($_GET){
setcookie("id",$_GET['userid'],time()+60*60*24*30);
}
echo("Welcome, {$_COOKIE['id']}!");
?>