Cookie

Learn Cookie in PHP

Cookiedemo.php

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
</head>

<body><center>
<?php
if (!isset($_COOKIE[‘name’])) {

setcookie(“name”, $_POST[‘name’]);
setcookie(“visits”, 1);

echo “Hello $_POST[name]. <br/>”;
echo “It appears that this is your first visit!”;

} else {
setcookie(“visits”, ++$_COOKIE[“visits”]);

echo “Welcome back, $_COOKIE[name]. <br/>”;
echo “You have visited us $_COOKIE[visits] times!”;
}
?></center>
</body>
</html>

 

Setcookie.php

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
</head>

<body>
<center><form action=”Cookiedemo.php” method=”post” name=”setcookie” target=”_self”>
<label>Name
<input type=”text” name=”name” />
</label>
<p>
<label>Submit
<input type=”submit” name=”Submit” value=”SetCookie” />
</label>
</p>
</form>
</center></body>
</html>

 

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.