Set Cookie: http://php.flashwebhost.com/vineesh/...set_cookie.php
PHP Code:
<?php
if (isset($_COOKIE['usersName'])) {
echo '<h2 style="color:#EF1725"> You are Mr.' . $_COOKIE['usersName'] . '. I told you na... </h2>';
echo 'To delete cookie, <a href="day_10_ex_7_del_cookie.php">click here</a>';
exit;
}
if (isset($_POST['usersName']) && strlen($_POST['usersName']) > 2) {
setcookie('usersName', $_POST['usersName'], time()+43200); //To remember for 12 hours
echo '<h3 style="color: #5EAE0E">I can remember you for 12 hours!. If you have doubt, refresh the window please...</h3>';
echo '<br>';
} else {
echo '
<html>
<body style="background-color:000589">
<table width="40%" align="center">
<tr>
<td>
<form method="POST" action="">
<h3 style="color: #FFFFFF">Enter your name: </h3>
<input type="text" name="usersName">
<button type="submit">Submit</button>
</form>
</td>
</tr>
</table>
</body>
</html>
';
}
Delete cookie: http://php.flashwebhost.com/vineesh/...del_cookie.php
PHP Code:
<?php
setcookie('usersName', "", 0);
echo '<h2>Cookie deleted</h2>';
echo '<br>';
echo 'To go back, <a href="day_10_ex_7_set_cookie.php">click here</a>';
Bookmarks