Download presentation
Presentation is loading. Please wait.
Published byΤρύφαινα Ζέρβας Modified over 6 years ago
1
Cookies Cookie :- A cookie is often used to identify a user. 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. A cookie is create by using setcookie() function Syntax setcookie(name, value, expire, path, domain, secure, httponly); Only the name parameter is required. All other parameters are optional.
2
Program to check whether a Cookie exists or not
<?php $cookie_name = ‘bca-5-test-cookie’; If (isset($_COOKIE[$cookie_name])); { echo ‘<b>’ . $cookie_name . ‘</b> is set’; } Else echo ‘<b>’ . $cookie_name . ‘</b> is not set ‘;
3
Cookies ‘$_COOKIE’ is global variable. Global variables are in built variables that are used for specific purposes, and $_COOKIE is the global variable that allows us to use cookie data. If we don’t use it, we cant access cookie data. Isset() function is used to check whether cookie is set or not.
4
Program to set/create a cookie
<?php $cookie_name = ‘bca-5-test-cookie’; $cookie_value = ‘ Testing browser cookie for BCA 5th Sem’; Setcookie ($cookie_name , $cookie_value);
5
Program to create a Cookie with expiry time
<?php $cookie_name = ‘bca-5-test-cookie’; $cookie_value = ‘ Testing browser cookie for BCA 5th Sem’; $expiry_time = time()+50; Setcookie($cookie_name, $cookie_value, $expiry_time);
6
How to view cookies in web browser ?
1.From the Tools menu, select Options. 2.If the menu bar is hidden press alt to make it visible. 3. At the top of the window that appears, click privacy. 4. To manage cookie settings, from the drop-down menu under "History", select Use custom settings for history. Enable or disable the settings by checking or unchecking the boxes next to each setting: 1. To allow sites to set cookies on your computer, select Accept cookies from sites. To specify which sites are always or never allowed to use cookies, click Exceptions. 2. To accept third-party cookies, check Accept third-party cookies. In the "Keep until:" drop-down menu, select the time period you wish to keep cookies on your computer. 3. To specify how the browser should clear the private data it stores, check Clear history when Firefox closes. Click Settings.... Check the items to be cleared when you close Firefox. To view or remove individual cookies, click remove individual cookies. To remove all cookies, from the History menu, select clear your recent history. Click the arrow next to "Details" to expand the menu, check the items you want to clear, and then click Clear Now.
7
Program to delete a cookie
You can delete a cookie by calling the same function setcookie() with the cookie name and any value (such as an empty string) and the time is need to be set in the past. <?php Setcookie (“username”, “ “, time()-3600); ?>
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.