Category: php


Using Cookie Variables in PHP

Setting cookies in php is pretty straight forward. There is a php function:


This function must be called before any anything else on the page or it will fail. There are two options to address this.

Use ob_start to Buffer content

  1. You can either make sure that setcookie() is the first thing you call in your script - which is often just not a possibility.
  2. Or, You can use the ob_start() and ob_end_flush() functions.

ob_start() and ob_end_flush() will buffer the content on a page until after the setcookie() variable has been created.

Expire Value is a Unix Timestamp

The expire value for php cookies must be a UNIX time-stamp:

Use the php time() function

time() + 3600_____1hr
time() + 1800_____30min
time() + 900______15min
time() + 450______7.5 min
time() + 225______3.25 min
time() + 112.5____1.125 min
time() + 56.25____.625 = 37.5 sec.

The rest of your script goes here


// Here you set the cookie

// The cookie is called logged_in and can be found

// in the directory that your browser keeps cookies.

setcookie('logged_in' , $cookieVal ,(time() + 3600)) or die('no cookie');

Retrieving and using the value stored in a php cookie is done with the $_COOKIE[''] super global variable.
//Retrieving cookie value

echo $_COOKIE['logged_in']

Author: D.Shaun Morgan

how to upload images and files php Upload Images to Webserver HTML Form PHP Function # UPLOAD FILE function upload_file(){ echo '

Storing image locations mysql Storing Image Url Location in Mysql Database Storing images in the Mysql Database using php can be done by encoding the whole image with a function called base64enco

php example post array php Visual example of how PHP handles the super-global array variable "$_POST" Author: D.Shaun Morgan Versions and Skill Level

how to install php 5 php This is a quick start beginner's how-to manual explaining how to quickly setup a PHP 5 installation on a Windows XP PC. You must have an Apache webserver installed and working on your personal comp

php passing variables php Pass Variables from One Page to Another -- PHP Author: D.Shaun Morgan Tutorial Outline : Passing PHP variables with $_


Leave a Comment


Name:      | Email:      | Website:



Enter The Above Security Code: