Reading Cookies : setcookie « Cookie Session « PHP






Reading Cookies

 
<?php
  $GLOBALS['username'] = "test";
  $GLOBALS['password'] = "test";
  
  setcookie ("cookie_user", "test", time()+60*60*24*30);
  setcookie ("cookie_pass", md5 ("test"), time()+60*60*24*30);
  
  function validatelogin (){
    if (strcmp ($_COOKIE['cookie_user'], $GLOBALS['username']) == 0 && strcmp ($_COOKIE['cookie_pass'], md5 ($GLOBALS['password'])) == 0){
      return true;
    } else {
      return false;
    }
  }
  
  if (validatelogin ()){
    echo "Successfully logged in.";
  } else {
    echo "Sorry, invalid login.";
  }
?>
  
  








Related examples in the same category

1.PHP 5 setcookie() Parameters
2.Assigning cookie names according to array index value
3.Cookie created
4.Deleting Cookies
5.Setting a cookie with a domain restriction
6.Setting a cookie with a path restriction
7.Setting an expiring cookie
8.Setting cookie expiration
9.Setting the cookie domain
10.Setting the cookie path
11.Setting the cookie path to a specific directory
12.Deleting a Cookie Using setcookie()
13.The cookie expires one day from now
14.Starting a page with setcookie()