Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Safe Mode

Status
Not open for further replies.

rudenborg

Programmer
May 18, 2004
19
US
Hi!

I am trying to get a website to work on a server with PHP running in safe mode. I have a couple problems so far:

I can't get "session_start()" and "header()" functions to work. I have them working on my local computer just fine -- so I'm assuming it has something to do with PHP safe mode.

My question is -- does this make sense? Would these problems be associated with PHP running in safe mode? And if so is there a way to work around them?

I'm getting pretty frustrated -- so any help would be appreciated!

Thanks!

Jonathan
 
Safe mode should not affect the functioning of session_start() or header(). The most likely culprit is the point at which you are invoking those functions in your code.

An HTTP transmission from a server to a browser consists of a set of HTTP headers, a blank line and the HTML body of the actual page. It is the blank line which tells the browser that the headers are complete and the body begins.

So if you have already sent some output to the browser, PHP and your web server have assumed that the headers are finished and have already sent that blank line. No more headers can be sent. And both session_start() and header() generate HTTP headers.

The sure sign that this is the problem is that you are getting an error which tells you "headers have already been sent".

There are two workarounds. One is to restructure your code so that the header-generating functions are invoked before you produce any output. The other is to use PHP's output control functions.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
That's the annoying part, it runs just fine on my person computer running Apache, it's the remote server that I'm having problems with.
 
Thanks for your help!

You were right with your first post, I had just written the script in such a way that it wasn't amediately apparent.

I fixed it so that the session call and header functions were the first part of the script to execute. Now it works without a problem.

I still don't know why it worked on my own computer with it coded wrong, but I'm not going to worry about it.

Thanks again,

Jonathan
 
Yup, output_buffering was on.

I should have been able to figure this one out -- o well...

Thanks again,

Jonathan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top