Link to home
Start Free TrialLog in
Avatar of beridius
beridius

asked on

php cookie

I need some code to:

when a user logs on the site they get a page that is not the main page (info.php)
but when the revist the site the dont get the page(info.php)
ASKER CERTIFIED SOLUTION
Avatar of amigura
amigura
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mark Brady
Can you try and re ask your question. What is it that you are trying to do? Do you want to set a cookie to let you know if a user has been to your site before or not?

If so, then a simple cookie to remember the users name would be something like this. For this example you would need to know their username and would be kept in the variable $username

<?php
$value = $username;
$cookieName = 'visitor';
setcookie($cookieName, $value, time()+3600*24*365);  /* expires in 1 Year */
?>

The above code will write and save a cookie on the users computer. The cookie name in this case will be 'visitor'. You can name this whatever you like. The cookie expires in 1 year. you can modify the code to make it any length you want or if you want to delete the cookie, set a date in the past and it will be deleted as soon as the browser is closed.

All it does is store the $username variable/value. To get the data in the cookie on another page or your main page you use this code...

<?php
if (isset($_COOKIE['visitor'])) {
// get the users name here
$username = $_COOKIE['visitor'];
}
?>

Now you have the username in the $username variable when they revisit your website.

Is this the sort of thing you are trying to achieve?

?>