setting a cookie from a form value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<?php
// this fails twice before working
// first with undefined index 'txt' on line 5
// then with undefined index 'val' on line 10 then it works
$name = $_POST['txt'];
setcookie("val",$name,time() + 24 * 60 * 60);

if(isset($_COOKIE) && !empty($_COOKIE))
{
    $var = $_COOKIE['val'];
    print('cookie = '. $var . '</br>');
}
else
    echo ' cookie not set </br>';
    


?>
<form action="" name="myform" method="post">
<input type="text" name="txt" id="txt" value="abcdef" />
<input type="submit" formmethod="post" />
</form>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux