Jump to content

HELP! how do I create a cookie?


aminnuto

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]
Link to comment
https://forums.phpfreaks.com/topic/25095-help-how-do-i-create-a-cookie/
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]

Archived

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

×
×
  • Create New...

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.