Jump to content

Archived

This topic is now archived and is closed to further replies.

aminnuto

HELP! how do I create a cookie?

Recommended Posts

I currently have use this code

[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?
[/code]

Share this post


Link to post
Share on other sites
See how you get on with this?

[code]
<?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);

?>
[/code]

[url=http://uk2.php.net/setcookie]PHP SetCookie Reference[/url]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.