views:

522

answers:

4

I am a beginner in PHP.

I am receiving the following errors. I cannot view the error from my computer on FF, IE, and Chrome, but yet I see the error up top when browsing from another computer's browser.

Warning: session_start() [function.session-start]: open(/tmp/sess_c464nadk4jsn4u43mpqipkjbr7, O_RDWR) failed: Permission denied (13) in "file location" on line X

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at "file location":line X) in "file location" on line X

Any ideas anyone?

I have the session_start() before the includes which means before any html, and the session is only used to carry over one variable.

I tried placing it before

Header("Cache-control: private, no-cache");
Header("Pragma: no-cache");

but this only generated more Warning signs. Any help would be appreciated!

A: 

The first error seems to indicate missing write permission in the temp directory but could be linked to the second one also.

The second error normally only happens when there is some kind of output is being sent from your php script before the session_start() call, because will automatically send HTTP headers. This can be any kind of html or even blank lines or spaces in the file before the actual call or before the <?php opening bracket. As Shane suggests in a comment, the reason for the second error could very well be that the error message from the first error (unable to write the session to a file in /tmp) causes headers to be sent and thus it is too late to send them with the header() call.

Knut Haugen
"line X" i replaced with on "line 4"
Juan
1: <?php 2: Header("Cache-control: private, no-cache");3: Header("Pragma: no-cache");4: session_start();
Juan
You should put session_start() before either of those headers.
AndyMcKenna
nope, sorry, that only generated more errors. thanks for your input.
Juan
+4  A: 

seems that the /tmp/ dir is not readable or writable by the user php is running as.

Jason
the page should not be writable, I am only using sessions to check for a string as a form is submitted on the same page.
Juan
It's not the page that its trying to write to, PHP stores all session information in a folder structure defined in INI under session.save_path. Regardless of what information is being stored in the session a file will be created. The permission problem is the first error followed by the second error which seems to be due to the first.
ShaneB
I agree with ShaneB - the error output from the first is causing the 2nd error. Fix you directory permissions problem and you're done.
Peter Bailey
I have changed the directory, and the file permissions to 777, still no good.
Juan
A: 
  • Is there any whitespace or any other character before the <?php starting tag?
  • Is the session_start() really the first statement within the php block?
Grzegorz Oledzki
at the top of the page I have: <?php Header("Cache-control: private, no-cache");Header("Pragma: no-cache");session_start();include('../includes/h.header.php');?>
Juan
+1  A: 

The "headers already sent" error is caused by the first one. The other answers here trying to debug it aren't going to help you. Fix the first error and the second will go away. The first error tells you what your problem is already - the /tmp directory is not writable by the web server. /tmp is usually 777 (rwxrwxrwx).

I just changed it the directory and the file permissions, didn't work.
Juan