You need to use sessions.
Basic tutorial:
Code:
<?php
/* script1.php
*
* session_start() does the following:
* If a session_id already exists, open up the session file related to that id
* and parse the data contained in that file into session variables, which are accessed
* in a script via the $_SESSION superglobal
* create new HTTP header information in the form of a cookie and output that cookie
* to the user's browser, if the user has cookie's enabled this will be one form of
* passing the session_id from one script to another.
* Because this function alters the outgoing HTTP response headers it must appear at
* the very beggining of a script before any output (e.g. from echo or print) and
* the opening php delimiter '<?php' may not contain white space or html content before
* it as that is considered to be output. However non-output producing code, like these
* comments are o.k.
*
* Read the following for more information
* http://www.php.net/session - all session related functions
* http://www.php.net/session_start
*/
session_start();
// Create a session variable for persistence
// The $_SESSION array is a special superglobal variable available in any scope
//
// More on PHP predefined variables:
// http://www.php.net/manual/en/languag...predefined.php
$_SESSION["foo"] = "Hi I'm persistent!";
$_SESSION["counter"] = 1;
echo "This session has been accessed: {$_SESSION["counter"]} times.";
?>
Now to create the persistence.
If users do not have cookies enabled you might want to hard code in the session_id and pass it to every page that uses session data (a good idea!). The session id is a randomly generated string of letters and numbers that PHP uses to tie session data to the current user.
One method is with url embedded arguments a.k.a. query strings a.k.a. the get method:
echo "<a href='some_session_page.php?sid=".session_id()."'> another session page</a>";
http://www.php.net/session_id
-OR-
echo "<a href='some_session_page.php?".SID."'>another session page</a>";
'SID' is a special predefined constant that will contain the entire string needed for a URL embedded argument.
Using the post method:
echo "<input type='hidden' name='sid' value='".session_id()."'>";
You may use either 'sid' or 'PHPSESSID' as the name of the session.
You don't have to do anything special for cookies, cookies are always used by default, unless you explicitly turn them off in php.ini.
Now you can access the variables we set above on another page:
Code:
<?php
// some_session_page.php
// Always make a call to session_start() on a page that uses session data
session_start();
// If this variable exists and its a number, do the following
if (isset($_SESSION["counter"]) && is_numeric($_SESSION["counter"]))
{
$_SESSION["counter"]++;
echo "This session has been accessed: {$_SESSION["counter"]} times.<br />";
}
// If this variable exists and it isn't an empty value (false, null, empty string, zero, string zero)
if (isset($_SESSION["foo"]) && !empty($_SESSION["foo"]))
{
echo $_SESSION["foo"]."<br />";
}
?>
See there, pretty easy stuff!
hth,
: )
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::