Chapter12 - Chapter 12 Using PHP With Cookies and MySQL...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Using PHP With Cookies and MySQL Chapter 12
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
12.1 Cookies
Image of page 2
Types of Cookies a cookie is a little text file that resides on the user's computer is placed there by the browser when the browser receives some information from the website's server. cookies have no evil intent; their main purpose is to identify users and possibly prepare some customizations on a web page when the user revisits the site cookies cannot carry viruses and cannot install malware on a user's computer authentication cookies allow a web server to know whether a user is logged in and which account the user is logged in under. Without such information, the site would not know whether or not to send sensitive information (such as logging in to a bank’s website) a session cookie exists only while a user is on a particular website is normally deleted by the browser when the user exits the browser a persistent cookie remains on the user's computer for a specified length of time, even after the user has left the site, exited the browser, and turned off the computer a secure cookie has the secure attribute enabled and is only used via HTTPS ensures that the cookie will be encrypted when transmitting from client to server a httponly cookie is supported by most modern browsers and is used when transmitting HTTP or HTTPS requests feature only applies to session cookies A third-party cookie is set with a different domain from the one that shows in the address bar of the browser often set by advertisers to gain information about what website a user has visited
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Writing Cookies the setcookie() function defines a cookie must be called before any output, including the <html> and <head> tags after a cookie has been set, it can be accessed the next time the page loads using the $_COOKIE superglobal or $_REQUEST setcookie() function accepts up to six arguments, all but $name are optional general syntax for this function: bool setcookie(string $name [, string $value [, int $expire = 0 [, string $path [, string $domain [, bool $secure = false [, bool $httponly = false ]]]]]] ) explanation of the parameters in this function: $name : the name of the cookie $value : the value stored on the client's computer, will be retrieved by the server $expire : sets the expiration date of the cookie time is expressed in number of seconds since a specific date/hour/minute/seconds $path : the path on the server in which the cookie will be available $domain : the domain to which the cookie is available $secure : a boolean, set to either true or false $httponly : a boolean, is accessible only through the HTTP protocol when set to true and, if true , the cookie will not be accessible to other scripting languages like JavaScript
Image of page 4
The time() Function time() function returns the current time measured as the number of seconds since the Unix epoch is the number of seconds since January 1, 1970 00:00:00 GMT there are 86,400 seconds in one day the time() function sets a base time and then we can add
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern