newbie: using start_session

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am learning PHP5. I would like to use session mechanism.
In a file Paper.php I have written:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  
" ">
<html xmlns=" ">
if (isset($_SESSION['Error']))

In another document I use Paper.php:

    $_SESSION['Error'] = '...';
    header("Location: Paper.php");

The problem is that after redirect I receive a message:

Fatal error: Call to undefined function start_session() in  
F:\Inetpub\wwwroot\StowarzyszenieIntegracja\AddOpinion.php on line 5

What should I do to use start_session() function?

Re: newbie: using start_session


Quoted text here. Click to load it

First error: session_start() must be called _before_ any other output.
Obviously your error_reporting directive is misconfigured, because you
would have got an E_NOTICE error. Set error_reporting to E_ALL|E_STRICT
in your php.ini.

Not an error, but a question: Why XHTML? Why not just HTML (Strict)?

Quoted text here. Click to load it

Second error: The Location header requires an absolute URL.

Quoted text here. Click to load it

Third error: The function is named session_start(), not start_session().


Re: newbie: using start_session

R.A.M. wrote:
Quoted text here. Click to load it

That's correct.  You put your DOCTYPE before the session_start() call.

session_start(), header() and other functions which affect he header  
must be sent before ANY output to the browser.  This includes any HTML,  
as well as PHP output.

The reason for this limitation is the HTTP protocol.  Before the server  
can send any output to the client, the server must send the headers.  
But you can't modify the headers once they've been sent.  So you have to  
  do the modifications before any output is sent.

And start_session() usually uses cookies, which are sent in the header.  
  So you need the call to start_session() before any other output.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline