EDIT: Forgot to answer...
I didn't say not to use sessions altogether, I just asked why sessions need to be automatically started for every single page request. Can you say that every single .php file on your site (now and in the future) requires session data? Most can not, thus the default value set by the developers of PHP is for session.auto_start to be disabled.[/QUOTE]
i need the session started automatically because i noticed that if i don't, i have to start it manually in every page i like to check on the array $SESSION's values.
Or else $SESSION['myvar'] will be empty....
so since i need to check if a user has been logged and i do this by a SQL query like
(Just for example)
SELECT *FROM authorizedUsers WHERE login=$_SESSION['username']
and i need to include this code at the top of every page... or else a user who comes to know the url of a internal page could see the contents bypassing the login....
since this is included in every page of this site.... i need to start session in every page....
is there a better way for this? do I miss something?
fro the session expiration following your suggestion i found this code:
session_start();
if(!session_is_registered("session_count")) {
$session_count = 0;
$session_start = time();
$_SESSION['session_count']=$session_count;
$_SESSION['session_start']=$session_start;
} else {
$session_count++;
}
$session_timeout = 20; // 30 minutes (in sec)
$session_duration = time() - $_SESSION['session_start'];
if ($session_duration > $session_timeout) {
session_unset();
session_destroy();
$_SESSION = array();
die("SIGN OUT");
//header("Location: /login_page.php?expired=yes"); // Redirect to Login Page
} else {
$session_start = time();
$_SESSION['session_start']=$session_start;
}
as u can see even here... u need to start session... or else $_SESSION['session_start'] will be void.... n' the script won't work.....
so finally why bothering starting session in all pages? when we can use session_autostart?😕