Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

PHP - Getting good with cookies

1.142 Aufrufe

Veröffentlicht am

Getting good with cookies

  • Als Erste(r) kommentieren

  • Gehören Sie zu den Ersten, denen das gefällt!

PHP - Getting good with cookies

  1. 1. PHP Cookies [email_address]
  2. 2. What is Cookies? <ul><li>A cookie is a small file that the server embeds on the user's computer. </li></ul><ul><li>A cookie is often used to identify a user. </li></ul><ul><li>Each time the same computer requests a page with a browser, it will send the cookie too. </li></ul><ul><li>With PHP, you can both create and retrieve cookie values. </li></ul>
  3. 3. How to Create a Cookie? <ul><li>setcookie(name, value, expire, path, domain); </li></ul><ul><li>The setcookie() function must appear BEFORE the <html> tag. </li></ul><ul><li>The value of the cookie is automatically URLencoded when sending the cookie, and automatically decoded when received (to prevent URLencoding, use setrawcookie() instead). </li></ul>
  4. 4. Example - Cookies <?php setcookie(&quot;user&quot;, “mni&quot;, time()+3600); ?> <html> <body> </body> </html> Create a cookie named user Assign a value to the cookie (user) The cookie will expire in ONE hour
  5. 5. How to Retrieve a Cookie Value? <html> <body> <?php if (isset($_COOKIE[&quot;user&quot;])) echo &quot;Welcome &quot; . $_COOKIE[&quot;user&quot;] . &quot;!<br />&quot;; else echo &quot;Welcome guest!<br />&quot;; ?> </body> </html> Retrieve a value from a cookie called user
  6. 6. How to Delete a Cookie? <?php setcookie(&quot;user&quot;, &quot;&quot;, time()-3600); ?> Set the expiration date to ONE hour ago Reset the value of cookie
  7. 7. Discussion <ul><li>Advantages of using cookies </li></ul><ul><li>Disadvantages of using cookies </li></ul>

×