LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-13-2006, 02:39 AM   #1
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Rep: Reputation: 30
php 5.0.4 - Why are sessions not working


The sessions are not working in php5.0.4.

In earlier versions the same was working. Even the simple scripts as below are not working.

Code:
<?php
// page1.php

session_start();

echo 'Welcome to page #1';

$_SESSION['favcolor'] = 'green';
$_SESSION['animal']   = 'cat';
$_SESSION['time']     = time();

// Works if session cookie was accepted
echo '<br /><a href="page2.php">page 2</a>';

// Or maybe pass along the session id, if needed
echo '<br /><a href="page2.php?' . SID . '">page 2</a>';
?>
and

Code:
<?php
// page2.php

session_start();

echo 'Welcome to page #2<br />';

echo $_SESSION['favcolor']; // green
echo $_SESSION['animal'];   // cat
echo date('Y m d H:i:s', $_SESSION['time']);

// You may want to use SID here, like we did in page1.php
echo '<br /><a href="page1.php">page 1</a>';
?>
Any help ?


Prabhat Soni
 
Old 03-13-2006, 03:34 AM   #2
climbingmerlin
Member
 
Registered: Mar 2004
Location: UK
Distribution: Fedora, OpenSuse
Posts: 91

Rep: Reputation: 15
what error messages are you getting in the apache logs? If you are getting segmentation faults then it could be to do with some of the PHP packages that you have installed.

I had the same problem, and I removed all the PHP packages that I was not using for my build and the session problem went away.
 
Old 03-13-2006, 04:45 AM   #3
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
Check your php.ini and make sure the session.save_path is set to somewhere writable.
 
Old 03-13-2006, 06:42 AM   #4
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
Hello friends,
In php.ini:
session.save_path = "/var/lib/php/session"

The permissions of this directory are : drwxrwx---

The httpd log is
log
Code:
PHP Warning:  session_start() [<a href='function.session-start'>function.session-start</a>]: 
open(/var/lib/php/session/sess_m4hrl8r4cqfv3vttctdg9bm6c1, O_RDWR) 
failed: Permission denied (13) in /var/www/html/main_menu.php on line
 2[client 127.0.0.1] PHP Notice:  Undefined index:  user_id in 
/usr/include/php/include/genl_func.php on line 62

[client 127.0.0.1] PHP Notice:  Undefined index:  user_id in 
/var/www/html/main_menu.php on line 5

[client 127.0.0.1] PHP Warning:  Unknown: 
open(/var/lib/php/session/sess_m4hrl8r4cqfv3vttctdg9bm6c1, O_RDWR) 
failed: Permission denied (13) in Unknown on line 0

[client 127.0.0.1] PHP Warning:  Unknown: Failed to write session data
 (files). Please verify that the current setting of session.save_path 
is correct (/var/lib/php/session) in Unknown on line 0
I changed permissions to drwxrwx-wx

But still it does not work.


Prabhat Soni

Last edited by prabhatsoni; 03-13-2006 at 06:43 AM.
 
Old 03-13-2006, 06:52 AM   #5
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
chown the directory to whoever httpd runs as.
 
Old 03-15-2006, 10:50 PM   #6
prabhatsoni
Member
 
Registered: Oct 2004
Location: India
Distribution: FC 12
Posts: 233

Original Poster
Rep: Reputation: 30
Hello,
Sorry for taking time to respond. In fact I was out of station for a few days. And In India "HOLI" the festival of colors is celebrated with much gusto and enthusiasm, and I was busy in it.

Ok, the problem.

After changing the permissions of the directory /var/lib/php/sessions to drwxrwx-wx, I shut down the PC and restarted it, and I find that the sessions are working ok.

Thanks a lot for this help.


The directory is owned by root. Would not it create any problem if instead of allowing "others" to "write" and "cd" into it, I simply chown it to apache.
What is the established norms or practice. Ibelieve both would serve the purpose insofar as the sessions are concerned. Will it have any implications for the security ?


Prabhat Soni

Last edited by prabhatsoni; 03-15-2006 at 10:54 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sessions in PHP zowey Programming 2 12-26-2004 06:35 PM
Troble on PHP Sessions Gerardoj Programming 4 05-25-2004 01:03 PM
Problem with php sessions sashhoney Linux - Software 7 08-28-2003 07:30 AM
Apache PHP and sessions Satriani Programming 0 04-21-2003 11:55 AM
PHP Sessions RecoilUK Programming 1 04-21-2002 05:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration