Presentation is loading. Please wait.

Presentation is loading. Please wait.

COOKIES and SESSIONS. COOKIES A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each.

Similar presentations


Presentation on theme: "COOKIES and SESSIONS. COOKIES A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each."— Presentation transcript:

1 COOKIES and SESSIONS

2 COOKIES A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

3 HOW TO CREATE A cookie is created with the setcookie() function. setcookie(name, value, expire, path, domain, secure, httponly);

4 EXAMPLE <?php $cookie_value = “Zhangali Pernebayev"; setcookie(“user”, $cookie_value, time() + (86400 * 30), "/"); ?>

5 Modify a Cookie Value

6 Delete a Cookie To delete a cookie, use the setcookie() function with an expiration date in the past:

7 Check if Cookies are Enabled The following example creates a small script that checks whether cookies are enabled. First, try to create a test cookie with the setcookie() function, then count the $_COOKIE array variable: 0) { echo "Cookies are enabled."; } else { echo "Cookies are disabled."; } ?>

8 Difference between COOKIES and SESSIONS The main difference between cookies and sessions is that cookies are stored in the user's browser, and sessions are not. This difference determines what each is best used for. A cookie can keep information in the user's browser until deleted. If a person has a login and password, this can be set as a cookie in their browser so they do not have to re-login to your website every time they visit. You can store almost anything in a browser cookie. The trouble is that a user can block cookies or delete them at any time. If, for example, your website's shopping cart utilized cookies, and a person had their browser set to block them, then they could not shop at your website.

9 THANKS!!!


Download ppt "COOKIES and SESSIONS. COOKIES A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each."

Similar presentations


Ads by Google