Presentation: PHP and MySQL: Chapter 12 Cookies and Sessions [Slides 1-19]
What is the only required parameter in the session_set_cookie_params function?
$lifetime
What are the three typical uses for cookies?
1.) Allow users to skip login and registration forms that gather data like username, password, address, or credit card data. 2.) To customize pages that display information like weather reports, sport scores, and stock quotations. 3.) To Qqcodu
How to enable or disable cookies in Chrome
1.) Open the "Customize and control Google Chrome" menu. 2.) Select the Settings item. 3.) Click on the link to the "Privacy and security" section. 4.) In the "Privacy and security" section, click on the "Cookies and other site data" link. 5.) Select the "Allow all cookies" option to enable cookies or the "Block all cookies" option to disable cookies.
Browsers generally accept only ____ cookies from each site and _____ cookies total.
20, 300
Browsers can also limit each cookie to __ kilobytes
4
What is a cookie?
A cookie is a name/value pair that is stored in a browser.
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly)
If TRUE, the cookie is only available if it is sent using HTTPS. The default is FALSE.
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly)
If TRUE, the cookie is only made available through the HTTP protocol and not through client-side scripting
Per-session cookie:
If you set the $expire parameter to 0, the cookie only exists until the user closes the browser
persistent cookie
If you want, you can set the $expire parameter to a date up to three years from the current date. In that case, the cookie stays in the browser until the expiration date.
How to delete cookie?:
Set the value to the empty string and the expiration date to a time in the past. Any remaining parameters must have the same values as when the cookie was originally created.
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly)
The domain that the cookie is available to. The default is the name of the server that's setting the cookie.
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly)
The expiration date of the cookie as a timestamp. If set to 0, the cookie expires when the user closes the browser. Default value is 0.
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly)
The path on the server that the cookie is available to. If set to '/', the cookie is available to all directories on the current server. The default is the directory of the PHP file that is setting the cookie.
To provide session tracking when cookies are disabled, you can use _______ to store the session ID into the URL for each page of an application (not recommended)
URL encoding
How to get the cookie the next time the browser requests the page?
You can use the superglobal $_COOKIE variable. This variable is an associative array where the cookie name is the key and the cookie value is the value.
On the client, the browser saves the cookie and sends it back to the server every time it
accesses a page from that server.
The session_set_cookie_params function must be called _____ the session_start function
before
On the server, a web application creates a cookie and sends it to the
browser.
By default, cookies only last until the user____ However, cookies can be set to persist in the user's browser until a specified expiration date.
closes their web browser.
By default, PHP uses a _____ to store a session ID in each browser. Then, the browser passes the cookie to the server with each request.
cookie(?)
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly)
name of the cookie
By default, a session uses a _____ cookie to associate a browser with the data for its session. You can use the session_set_cookie_params function to customize the cookie for the session.
per-session
To maintain state, a web application uses
session tracking
how to start a session (session tracking) ?
session_start() ----------------------- starts a new session or resumes a previous session. returns TRUE if successful and FALSE otherwise. This function must be called before the page sends any HTML output to your application.
You set a cookie using the ___- function?
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly)
You can use the ____ function to remove an element from the $_SESSION array.
unset
setcookie($name, $value, $expire, $path, $domain, $secure, $httponly)
value of the cookie. Default is empty array.