PHP Cookies

By | 26/04/2012

 

cookies are used to store the data in browser.

Cookies of the webpage should be created before the HTML tag. Therfore setcookie(); function will be used first of the webpage.

Select Code
1
</p> <p><?php<br /> setcookie(name, value, expire, path, domain);<br /> ?></p> <p>

 

Here setcookie(); function will create a cookie with name “tobby” , value as “tobby cook” and expires after 1 hour from cialis 20 mg the time viagra with food of creation.

time()+3600 will makes the cookie viagra einnahme to be expire in 1 hour i.e., 60 seconds * 60 minutes

Select Code
1
<br /> <?php<br /> setcookie("Tobby", "tobby cook", time()+3600);<br /> ?><br /> <html><br /> </html><br />

 

Display the cookies

The cookie “tobby” will store the value “tobby cook”. $_COOKIE[‘tobby’]; will display “tobby cook”.

Select Code
1
</p> <p><?php<br /> echo $_COOKIE[‘tobby’];<br /> ?></p> <p>

 

Check whether cookie is present or not

Select Code
1
</p> <p><?php<br /> <a style="text-decoration: none; color: inherit; cursor: default; outline: none;" href="http://cialisonline-storeedtop.com/">cialis online</a>  if(isset($_COOKIE[‘tobby’]))<br /> <a style="text-decoration: none; color: inherit; cursor: default; outline: none;" href="http://cialisgeneric-toped.com/">side effects of cialis</a>  {<br /> echo “Cookie named Tobby already created”;<br /> }<br /> else<br /> {<br /> echo “Cookie named Tobby oesn’t exists2”;<br /> }<br /> ?></p> <p>&nbsp;</p> <p>

 

Deleting the cookies

For cookie to be expire in one day – 86400 ( 60 seconds * 60 minutes * 24 hours)

time()+86400 or time()+60*60*24

For cookie to be expire in one month – 2592000 ( generic cialis reviews 60 seconds * 60 minutes * 24 hours * 30 days)

time()+2592000 or time()+60*60*24*30

When http://viagrageneric-edtop.com/ we need to delete the cookie before the browser closes, time () with negative value will be used.

Select Code
1
<br /> <?php<br /> setcookie("Tobby", "tobby cook", time()-1);<br /> ?><br /> <html><br /> </html><br />

 

Post By prasad (110 Posts)

Website: →

Connect

About prasad

Prasad K has written 110 post in this blog.

Category: php

Leave a Reply