1 / 6

PHP Cookies

PHP Cookies. PHP Cookies. Cookies are small files that are stored in the visitor's  browser. Cookies can be used to identify return visitors, keep a user logged into a website indefinitely, track the time of the user's last visit, and much more .

Download Presentation

PHP Cookies

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP Cookies

  2. PHP Cookies • Cookies are small files that are stored in the visitor's browser. • Cookies can be used to identify return visitors, keep a user logged into a website indefinitely, track the time of the user's last visit, and much more. • Cookies accept seven different arguments, but only the "name" is required.  (Keep in mind that all values are stored on the visitor's computer, so the data is not private. Never store passwords in cookies, for example!)

  3. Argument Description • name Name of the Cookie • value Value of the Cookie • expire Time When Cookie Expires (Unix Timestamp) (If "0", Or Omitted, Cookie Will Expire When Browser Closes) (Set to Client's Time, Not Server's) • path Server Path Where Cookie Is Available (If Path Is the Root Directory, Cookie Is Available In Entire Domain) (Default Value Is Current Directory) • domain Domain That Cookie Is Available • secure Indicates That Cookie Should Only Be Transmitted Over a Secure HTTPS Connection From Client • httponly When TRUE, Cookie Is Only Accessible Through HTTP Protocol

  4. PHP allows you to create, retrieve and update cookies. • The setcookie() function is used to first create a cookie. • This function must be run before any other data is sent to the browser, such as the opening <html> tag or random whitespace. • The syntax is: setcookie(name, value, expire, path, domain); <?phpsetcookie("Example", "Whatever Value I Want", time()+2592000);?>

  5. <?phpsetcookie("Example", "Whatever Value I Want", time()+2592000);?>

  6. Retrieving the "value" that is stored in our cookie <?php  if (isset($_COOKIE["Example"])) {    echo $_COOKIE["Example"];  } else {    echo "No Cookie Named 'Example' Is Set";  }?>

More Related