Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Session not Saving

Tags:

php

session

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.

like image 208
Samir Avatar asked Jan 23 '12 18:01

Samir


People also ask

Why PHP session not working on 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.

Do PHP sessions expire?

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.

What is default timeout for session in PHP?

1440 seconds is the default which is actually 24 minutes.

How long is session timeout in PHP?

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.


1 Answers

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!'; 
}
like image 161
powtac Avatar answered Nov 06 '22 13:11

powtac