http://php.flashwebhost.com/sherly/cookies.php
Code:<?php if (isset($_COOKIE['bakery_visitor'])) { echo $_COOKIE['bakery_visitor'] . ', Welcome to Himalaya Bakery, eat some $_COOKIE'; exit; } if (isset($_POST['bakery_visitor']) && strlen($_POST['bakery_visitor']) > 5) { // time()+2800 = 2 hour, that is cookie will remember your name for 2 hour. // time() is a PHP function, that return current time in numric format. // 2800 == number of seconds in 2 hour. // So to remember 4 hour, use time() + 2800 * 4 setcookie('bakery_visitor', $_POST['bakery_visitor'], time()+2800); echo 'Cookie Set. Close the browser. Revisit this page, I will remember your name'; } else { echo ' What is your name ? <form method="post" action=""> <input type="text" name="bakery_visitor"> <button type="submit" name="whatever">Enter your name</button> </form> '; }




Reply With Quote

Bookmarks