Setting Cookies

Dismounted

59.***.***.***
1,440 days ago

Setting Cookies

Setting Cookies In this tutorial you are going to learn how to set and read cookies. Lets say you want to tell whether or not the visitor of your site has visited before. This is fairly easy to do and first you need to use the setcookie function in php. Copy this code to the very top of your page, before all headers and above the tag.

PHP code:

<?php // Set a Cookie setcookie("visited", "yes", time()+3600); ?>

To read the cookie and display whether or not the visitor has visited before, we are going to basically rely on the else if statements and call simple variables. To display the data, we need to call the cookies that were set in the above code. Copy this where you would like to display the data. [COLOR=Black]

PHP code:

<?php if ( isset( $_COOKIE['visited'] ) && $_COOKIE['visited'] == "yes" ) { echo ("Welcome back!"); } else } echo ("This is your first visit, Welcome!"); } ?>

[/COLOR]