Website Design United States, Website Design California, Website Designing United States, Website Designing California

Sending and Retrieving Cookies Using PHP - PHP

This is a very basic example of using cookies in PHP. They certainly can be very handy, especially if you hash the data using either the PASSWORD function or the MD5 function.

<?php

// Simple Cookie Sending and Reading
// by Mark Schweikert

// Send your cookie to the user's machine

// setcookie("Name_of_Cookie", "Value_of_Cookie", Time_of_Expiration, Path, Your_Domain.com, Bool_Secure)

// Name_of_Cookie = cookie name that will appear on user's machine and also the name you will call to retrieve the
// cookie value back to your server.
// Value_of_Cookie = what ever you need to store on the user's machine.
// Time_of_Expiration = how long the cookie will stay on the user's machine, in our example we use zero which will make
// the cookie delelte when the user closes the browser.
// Path = where the cookie will be available on the server, "/" makes it available everywhere.
// Your_Domain.com = the domain where the cookie will be used.
// Bool_Secure = set this to one(1) if the cookie can only be used with an https connection, zero(0) if security isn't necessary.

$Cookie_Value = "The info you wanted";
SETCOOKIE("My_test_cookie","The info you wanted", 0, "/", "www.yourdomain.com", 0);
echo "You sent a cookie with the value: $Cookie_Value<br><br>";

// Read the cookie from the user's machine

//$_COOKIE[Name_of_Cookie]

// Name_of_Cookie = the name of the cookie you sent using SETCOOKIE
$Retrieved_Cookie = $_COOKIE[My_test_cookie];
echo "The cookie you read from the user's machine has the value: $Retrieved_Cookie";

?>

WEB DESIGN INDIA
42 B Malviya Nagar , New Delhi-110017

Skype: manmeetsi
Email: support.webdesignindia@gmail.com
Tel: 91-011-40502005, 9810067295

 















 


© 2008-2009 dotnet4all.com