I have this written at the very first line on every page of my website.
include("restd.php");
and restd.php contains the following lines :
@session_start();
if(isset($_SESSION['id']))
{
}
else
{
header("location:index.php");
}
The problem i'm facing is that when ever i click or do something on my website. it logs me out and takes me to index.php.
im sure its something to do with the session. ive tried every single thing to avoid this problem but i ahve used restd.php because i dont want anyone to copy the url of someone and paste and get into the website.
anyone who is logged in only can view other's pages. if they arent logged in then they'll be redirected to index.php
EDIT : and guys a confusing thing is that all this is working fine on my testing server which is easyPHP-5.3.8.0 but this problem is coming up when i upload all the files to my server.
There are various reasons why a php session doesn't last. You need to specify how long the cookies last. You need to specify how long a session should persist on the server before garbage collection removes it. If you have multiple websites and you store the sessions on each server.
By default, a session in PHP gets destroyed when the browser is closed. Session timeout can be customized, to make the user's page inactive after a fixed time. Starting session: The PHP, session_start() function is used to start a session in the web page.
1440 seconds is the default which is actually 24 minutes.
The session expires after 30 minutes if the user does not send the request to the server. The latter part of the isset() function checks the total active time of the session. 1800 denotes 1800 seconds which is equivalent to 30 minutes. If the total active time exceeds 30 minutes, the if condition will be true.
Your session directory (probably /tmp/
) is not writable.
Check with session_save_path()
if it is writable.
if (!is_writable(session_save_path())) {
echo 'Session path "'.session_save_path().'" is not writable for PHP!';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With