PHP Cookies - RMB Scripting
You appear not have have an account with us, Click HERE to register an account...
RMB Scripting
Navigation
  Home
  Contact
  FAQ
  Forum
  Topsites
  Members
  Affiliates
  Arcade <-- New!
  IoxHost
Downloads
  Templates
  Scripts
  Fonts
  Image Sets
  Software
  Other
 
Tutorials
  .htaccess
  Photoshop
  C/C++
  CSS
  Macromedia Flash
  MySQL
  PHP
  PHP - User System
  HTML
  Javascript
  Macintosh
  Macromedia Fireworks
  Visual Basic
  Visual C#
  Windows
  Python
  Other
 
Latest Tutorials
Single VS Double
Understanding Variables
C# Server Port Check
All PHP / Apache Funct...
Block User\'s Direct A...
Latest Comments
Users Online
Users Online
Single VS Double
Single VS Double
Liveprinter For Mac
Stats
Total Members: 568 [220]
Total Tutorials: 272
Newsest User: noelm
Todays Unique Hits: 68
Users Online: 0
 
5 Guests
Poll
Should we change our name?
Hmmmm, Yes!!
Maybe
Depends on what to
NO!
Main Content
Tutorial: PHP Cookies By DanielXP
Cookies hold information on your hard drive saved from a website. From passwords to security validation information.

Important:
Remember to include ob_start(); at the top of each page you use cookies on!

How to set a cookie:
   
PHP:
<?php
ob_start
();
$cookievalue "some value to be stored";
setcookie("COOKIENAME"$cookievaluetime()+600);
?>


The variable "$cookievalue" is the data to be saved in the cookie.
setcookies is the PHP funtion we are going to use.
"COOKIENAME" is the name of the cookie to be save, This could be any thing from "password" to "username".
Then the variable is set as the cookie value.
Then we can set when the cookie will expire. This is in seconds. 600 seconds is 10 minutes.

Now we have set a cookie lets find out how to display it on the page.

Displaying the value of a cookie:
   
PHP:
<?php
ob_start
();
echo 
$_COOKIE["COOKIENAME"];
?>


echo is to display the value on the page.
Then we tell the code that we want to display a cookie using $_COOKIE to get all the cookies set by the site.
Then we tell what cookie we are looking for in this place it is "COOKIENAME" which you will change to fit your cookie.

Now we have set a cookie lets learn how to delete it.

Deleting a cookie:
   
PHP:
<?php
ob_start
();
setcookie("COOKIENAME"""time()-600);
?>

The setcookie tells which funtion we would like to use.
"COOKIENAME" is the name of the cookie we would like to delete.
Then the value is set to "" which is nothing. (NULL)
Then we set the time to minus 10 minutes which will make the cookie expire.
Difficulty: Easy
Views: 1135
Rating:
Comments
There are currently no comments for this tutorial.
Notice:
Remember to post long codes on our pastbin! - (http://rmb.pastebin.com/)
Add Comment
You must be logged in to post a comment.
Good Morning Guest
Username: 
Password: 
Remember Username
Links
RMB Arcade
$2.50 Resellers
Free Domains
Free Games
Affiliates