PHP tutorials, html tutorial, photoshop tutorial, ajax tutorials,java tutorial, web design tips tutorials, css tutorial, visual basic tutorial, dreamweaver tutorial, php tutorial, html tutorials, c++ tutorial, javascript tutorial, windows tutorials, free flash tutorials, free photoshop source codes, sql tutorial
Web Development Tutorials, Programming Tutorials, PHP Script Index
Home | Forums | Downloads | Books | Submit Content | Links

Programming Articles

  PHP articles
  MySql articles
  Visual Basic.Net articles
  Java articles
  ASP articles
  ASP.Net articles
  Visual Basic articles
  CSS articles

Programming Tutorials

  PHP tutorials
  MySql tutorials
  Visual Basic.Net tutorials
  Java tutorials
  ASP tutorials
  ASP.Net tutorials
  Visual Basic tutorials
  HTML tutorials
  CSS tutorials

Programming Source Codes

  PHP scripts
  Visual Basic.Net scripts
  JavaScript scripts
  ASP scripts
  ASP.Net scripts
  Visual Basic scripts

Our Partners

  Free Resources
  Publisherbank
  Free Link Directory
  PHP Magazine
  Webmaster Passion
  Search Engine Bank
  Free Directory Site
  Free PHP Scripts
  Links Shopping Mart
  Variety Bazar
  Urdu Office Tutorials
  Evernew Scripts
  Evernew Scripts
  Evernew Directory
  Our Achievements
  Web templates
  Buy and Sell Templates
  Text Link Traders
  Directory Metro
  Gifts Choice
  Valentines Ecards
  Template Directory

Cookies in PHP

Date:2006-03-20

What is a Cookie?

The main purpose of cookie to identify a user. A Cookie is a small pieces of information that are stored in your web browser. Cookies are a huge hype these days, both for programmers and users, Users can store their username, email addresses and other important information. And programmers can easily collect information about users.

How to Create a Cookie
The setcookie() function is used to create a cookie.

  • Name : Name of the cookie.
  • Value : value of cookie variable name
  • Expire : The specified time when a cookie will be expired.
setcookie(name, value, expire, );

<?
setcookie ("cookie", "programmersbank.com", time()+36000);
//makes a variable $cookie with a value of "programmersbank.com"
?>

<html>
<body>
<p>
This cookie has a value programmersbank, and this cookie will expire after 10 hours
</p>
</body>
</html>

How to Retrieve a Cookie Value
When a cookie is set, PHP uses the cookie name as a variable.
To access a cookie you just refer to the cookie name as a variable.

<?php
if (!isset($_COOKIE["name"])) {

setcookie("name", $_POST["name"]);
setcookie("visits", 1);

echo "Hello $_POST[name]. <br />";
echo "It appears that this is your first visit!";

} else {
setcookie("visits", ++$_COOKIE["visits"]);

echo "Welcome back, $_COOKIE[name]. <br />";
echo "You have visited us $_COOKIE[visits] times!";
}
?>



Desclaimer | Privacy Policy | Submit Content | Links | Link to Us | Sitemap |Contact Us
Copyright Programming Tutorials, Web Development Tutorials, Source codes © All Rights are Reserved.
Powered By Evernew Solutions

Loans - Flights - Loans - Cheap Flights