Forum Moderators: coopster

Message Too Old, No Replies

Cookie storing

How to store info with it?

         

Richie0x

10:44 am on Apr 23, 2004 (gmt 0)

10+ Year Member



I have this script so far:


<?
session_start();
if (!isset($_SESSION['track'])) {
$_SESSION['track'] = 0;
} else {
$_SESSION['track']++;
}
?>

Which sets a cookie. I can also check if the cookie exists when the user goes to another page.

How do you store information in the cookie? For example if I want to store a number like 1200, and then get that information from the cookie again when they go to another page?

jamie

12:50 pm on Apr 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



richie,

just like you have done in the example above

$_SESSION['track'] = 0;

so in your case

$_SESSION['myvar'] = 1200;

on all other pages you can access the value through $_SESSION['myvar']

bgrobe

1:02 am on Apr 25, 2004 (gmt 0)

10+ Year Member



To define a session variable, you MUST use session_register("variable_name");!

jatar_k

2:46 pm on Apr 25, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



sorry bgrobe but you don't need to

... With $_SESSION, there is no need to use the session_register(), session_unregister(), session_is_registered() functions. Session variables are accessible like any other variables.

[ca.php.net...]