session_start not working

Status
Not open for further replies.

namiiii

New Member
Messages
4
Reaction score
0
Points
0
is there any reason why this will not work?

HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title></title>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    </head>
    
    <body>
        <form id="form1" method="post" action="default.php">
            <div>
                <?php
                    // initialize a session
                    session_start();
                    
                    // increment a session counter
                    $_SESSION['counter']++;
                    
                    // print value
                    echo "You have viewed this page " . $_SESSION['counter'] . " times";
                ?>
            </div>
        </form>
    </body>
</html>

i get the following error

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/myweb/public_html/sessions.php:12) in /home/myweb/public_html/sessions.php on line 14

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/myweb/public_html/sessions.php:12) in /home/myweb/public_html/sessions.php on line 14
You have viewed this page 1 times
 

YamiKaitou

Member
Messages
636
Reaction score
0
Points
16
session_start and headers() must be the FIRST thing in the document. If you output any HTML code before that, it will throw that error
 
Status
Not open for further replies.
Top