PHP 5 setcookie() Parameters : setcookie « Cookie Session « PHP






PHP 5 setcookie() Parameters

 
Parameter     Description

name          The name to set the cookie variable to and hence the name to access it with

value         The value of the current cookie

expire        When a cookie will expire (in the form of a Unix timestamp)

path          The directory where the cookie will be available for use

domain        The domain at which the cookie will be available

secure        Whether a cookie can be read on a non-SSL enable script

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








Related examples in the same category

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