PHP interesse |
|
Hoe kan ik met het onderstaande script ervoor zorgen dat de taal session zo lang mogelijk wordt opgeslagen? Nu verdwijnt deze na ongeveer een uur
//proc all page display
include('lang.php'); //language detector
class Session
{
var $lang; //Username given on sign-up
var $url; //The page url current being viewed
var $referrer; //Last recorded site page viewed
/* Class constructor */
function Session(){
$this->time = time();
$this->startSession();
}
function cf($filename){//function to clean a filename string so it is a valid filename
$fp = explode('/',$filename);
$num = count($fp);
return $fp[$num-1];
}
/**
* startSession - Performs all the actions necessary to
* initialize this session object. Tries to determine if the
* the user has logged in already, and sets the variables
* accordingly. Also takes advantage of this page load to
* update the active visitors tables.
*/
function startSession(){
session_start(); //Tell PHP to start the session
/* Set referrer page */
if(isset($_SESSION['url'])){
$this->referrer = $search = $this->cf($_SESSION['url']);
}else{
$this->referrer = "/";
}
/* Set current url */
$this->url = $_SESSION['url'] = $this->cf($_SERVER['PHP_SELF']);
/* Set user-determined language: */
//set up languages array:
$langs = array('en','nl');
//
if(isset($_GET['lang'])){
if(in_array($_GET['lang'],$langs)){
$this->lang = $_SESSION['lang'] = $_GET['lang'];
}
}
if(!isset($_SESSION['lang']) || !in_array($_SESSION['lang'],$langs)){
$this->lang = $_SESSION['lang'] = language();
}
}
};
/**
* Initialize session object - This must be initialized before
* the form object because the form uses session variables,
* which cannot be accessed unless the session has started.
*/
$session = new Session;
?>
//proc all page display include('lang.php'); //language detector class Session { var $lang; //Username given on sign-up var $url; //The page url current being viewed var $referrer; //Last recorded site page viewed /* Class constructor */ function Session(){ $this->startSession(); } function cf($filename){//function to clean a filename string so it is a valid filename return $fp[$num-1]; } /** * startSession - Performs all the actions necessary to * initialize this session object. Tries to determine if the * the user has logged in already, and sets the variables * accordingly. Also takes advantage of this page load to * update the active visitors tables. */ function startSession(){ /* Set referrer page */ if(isset($_SESSION['url'])){ $this->referrer = $search = $this->cf($_SESSION['url']); }else{ $this->referrer = "/"; } /* Set current url */ $this->url = $_SESSION['url'] = $this->cf($_SERVER['PHP_SELF']); /* Set user-determined language: */ //set up languages array: $langs = array('en','nl'); // if(isset($_GET['lang'])){ $this->lang = $_SESSION['lang'] = $_GET['lang']; } } if(!isset($_SESSION['lang']) || !in_array($_SESSION['lang'],$langs)){ $this->lang = $_SESSION['lang'] = language(); } } }; /** * Initialize session object - This must be initialized before * the form object because the form uses session variables, * which cannot be accessed unless the session has started. */ $session = new Session; ?>
|