PDA

View Full Version : session_start(); / sessions


lse123
06-19-2007, 04:43 PM
first code is in home-page , well to use the second code in a subpage, this is correct[to use $_SESSION['affiliate'] = $affiliate ? Please note that between home-page_____subpage may exist one or two pages , is needed any session program or reference to these vars in these one or two sub-pages ?


<?php
session_start( );
$affiliate = '10000'; //default value
if (isset($_COOKIE['aff']) && ($_COOKIE['aff'] != Null))
{
$affiliate = $_COOKIE['aff'];
}
else if (isset($_GET['aff']) && ($_GET['aff'] != Null)) {
$affiliate = $_GET['aff'];
setcookie("aff", $affiliate, time()+60*60*24*90); // 3 months
}
$_SESSION['affiliate'] = $affiliate ;
?>

<?php
session_start();
$affiliate_id = $_SESSION['affiliate'];
$email_text = "You book through affiliate ID: {$affiliate_id}";

?>

Fumigator
06-19-2007, 05:40 PM
Please note that between home-page_____subpage may exist one or two pages , is needed any session program or reference to these vars in these one or two sub-pages ?


You know, that's a good question. I wish I could test that right now. Seems like the session would still be valid even if you move to a page that does not access the session data. You might try putting a session_start() at the top of those pages that don't need to access the session data and see if the subpage suddenly has access to the session data.

CFMaBiSmAd
06-19-2007, 06:42 PM
Intermediate pages don't need a session_start() in order to maintain the session.

The web server, being stateless, does not care how you get between pages and it does not care about the last page you were on or the next page you go to. You can even browse to a different site and return back to a page with a session.

As long as the browser provides a valid session ID (via cookie or url parameter) and the session data file still exists on the server, the session will be resumed.