Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP sessions not working in server [duplicate]

Tags:

php

I am designing a website in php.After completing it i uploaded the things in server. The page was working fine in localhost. But after uploading, the page is not even loading. At the top of every page i included a page called startsession.php. the contents of this page is as follows:

            session_start();
            header("Pragma: no-cache");
            header("Cache-Control: no-cache, must-revalidate");
            header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

If I remove the session_start, it is working fine. The details of error is as follows:

Page in which Error Occured---Unknown

Line no in which error occured---0

Details Of the Error---Unknown(): open(/tmp/sess_723d94fdc8ae3569b1a641fd8799ece9, O_RDWR) failed: No such file or directory (2)

Error Code---2.

Please help me

like image 323
soumya Avatar asked Aug 05 '26 04:08

soumya


2 Answers

Check and make sure the path (/tmp) is writable by the user running the web server, as this may be a permissions problem. Also, you need to use the header() function BEFORE using session_start, as noted in the documentation:

http://php.net/manual/en/function.session-start.php

Since session_start may actually send the HTTP headers. Also, always make 100% certain you're using:

error_reporting(E_ALL)

like image 124
Kristopher Ives Avatar answered Aug 06 '26 18:08

Kristopher Ives


You can use your own directory where session save.

Put below code above session_start(); code.

$sessdir = dirname(dirname(__FILE__)).'/session_dir';
ini_set('session.save_path', $sessdir); 

Enjoy!!!!!!!!!!

like image 29
Sanjeev Kumar Jha Avatar answered Aug 06 '26 19:08

Sanjeev Kumar Jha



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!