|
Posted by windandwaves on 11/06/05 00:09
Hi Folk
Forgive me for asking such a basic question... I have a site where I want to
track the user from start till end... To do this, I have setup the
following structure for each page, referring to startup.php, where the
session is managed. Can anyone check that I am doing it right. I thought I
was doing it right, but then the site started doing really, really funny
stuff, basically loosing track of sessions ...
I want my application to be as portable as possible, so I want to override
all the php.ini values that are important.
Thanks in advance (TIA)
- Nicolaas
<?php
include_once("startup.php");
if ( !startup( ) ) {
die("could not load application");
}
...
...//page content here
...
echo '<a href="testme.php?'.sid(false).'">link one on the page</a>';
echo '<a href="testme.php?a=3'.sid(true).'">link two on the page</a>';
....
....//more page content here
....
?>
/*startup.php file: */
//function to start session
function startup() {
$expiry = 60 * 60 * 24 * 1000;
ini_set('session.cache_limiter', 'nocache');
ini_set('session.use_trans_sid', 1);
ini_set('arg_separator.output', "&");
ini_set('session.use_cookies', 1);
ini_set('session.use_only_cookies', 0);
setcookie("CookieTest", "t"); //set a cookie so next time we know if the
user can do cookies
ini_set('session.cookie_lifetime', $expiry);
session_start();
}
//function to include session ID in case they do not accept cookies
function sid($withamp) {
if($_COOKIE["CookieTest"] == "t") {
return '';
}
$s = session_id();
if($s) {
if($withamp) {
$v = '&';
}
$v .= 'PHPSESSID='.$s;
return $v;
}
}
/* end of startup.php */
Navigation:
[Reply to this message]
|