Jump to content


Photo

HELP! how do I create a cookie?


  • Please log in to reply
2 replies to this topic

#1 aminnuto

aminnuto
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 25 October 2006 - 08:21 PM

I currently have use this code

<?php
session_start();

if ($_SESSION['discount'])
{
include('/home/pire/www/products/DISCOUNT-course.php');
} else {
include('/home/pire/www/products/REGULAR-course.php');
$_SESSION['discount'] = "value";
}

?>


but its only for the session and I want save it for the first 10 visits before it expires (or if thats not possible, expire after 10 days).


Can anyone help me out with the code to do this?


#2 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 25 October 2006 - 08:58 PM

See how you get on with this?

<?php

$session = md5(uniqid(rand()));
SetCookie("CookieName", "$session", time() + 14400); // last number is expiration time in seconds, 14400 sec = 4 hrs

// Print an individual cookie
echo $_COOKIE["CookieName"];
echo $HTTP_COOKIE_VARS["CookieName"];

// Another way to debug/test is to view all cookies
print_r($_COOKIE);

?>

PHP SetCookie Reference

#3 aminnuto

aminnuto
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 25 October 2006 - 09:00 PM

thanks.  I'm kinda a novis to this.  How would i implement that.  Do i add the code to my existing code or do i alter it to point to my php files?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users