简体   繁体   中英

How To Set Cookie in php for userlogin page further I don't how to access

How To Set Cookie in php for userlogin page further I don't how to access. and more I want more clear explantation about cookie for instance if i access the data in session I could be accessed in any page with in that website.Here in cookie I don't what to do further. because if i read theory i can understand.But In real time project I don't know what to do next.kindly I request every to explain those topic to me I hope you understand my question.

My coding part:

<form name="f1" action="" method="post"/>
username:<input type="text" name="username"/>
password:<input type="password" name="password"/>
<input type="submit" name="submit"/>
</form>

<?php
if(isset($_POST['submit']))
{
setcookie("TestCookie", $_POST['username'],20);
}
?>
This is in view page:
<?php
if (isset($_COOKIE['TestCookie']))
{
echo $_COOKIE["TestCookie"];
echo "<br />";
}
?>

Try this -

setcookie("TestCookie",$_POST['username'],time()+3600);

Here, time()+3600 will expire your cookie in 1 hour.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM