Using Cookies with Authentication in PHP

Using Cookies with Authentication:

<?php
$cookie_name = “test”;
$cookie_value = “string”;
$cookie_expire = time()+10;
$cookie_domain = “127.0.0.1”;
$cookie_domain2 = “localhost”;
setcookie($cookie_name, $cookie_value, $cookie_expire, “/” ,$cookie_domain, 0);
setcookie($cookie_name, $cookie_value, $cookie_expire, “/” ,$cookie_domain2, 0);
?>
<HTML>
<HEAD>
<TITLE>Set Test Cookie</TITLE>
</HEAD>
<BODY>
<h1>Mmmmmmmm…cookie!</h1>
</BODY>
</HTML>
save this file as cookie.php and upload it to webserver.

<?php
if ($_COOKIE[test] == “string”) {
echo “Cookie Works now”;
}
else
echo “Cookies are not accessable”;
?>
save this file as access.php and upload it to webserver.

First Open cookie.php in browser it will set cookie and then open access.php it will show “Cookie Works now” for 10 seconds.

About the author

Being the CEO and Founder of ClecoTech International, Mr. Ashish Prajapati is dedicated towards his aim of mentoring young startups into a full-fledged businesses. He is helping startups from America, Europe, India, and various other countries through proper guidance and the use of latest technologies to develop their innovation and ideas into definite realities.

Leave a Reply

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