Page 1 of 1

Session Starts Error [Resolved]

Posted: Tue Sep 24, 2013 8:35 pm
by Epiales
I can't figure out why the error, as session is only called once:

Error Message:

Code: Select all

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/gameplay/public_html/index.php:26) in /home/gameplay/public_html/models/config.php on line 123
Line 26 on the index.php is where the <?php> starts for the form:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=windows-1252" http-equiv="Content-Type" />
<title>War of Mafia's</title>
<link href="style.css" rel="stylesheet" type="text/css" />

<link href="css/tabcontent.css" rel="stylesheet" type="text/css" />


    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

    <script LANGUAGE="Javascript">

    function open_pop(){
    window.open('emot_box.html','mywin','left=20,top=20,width=470,height=230,toolbar=1,resizable=1');
}

    </SCRIPT>
    <script src="js/jQuery.js" type="text/javascript"></script>
    <script src="js/refresh_message_log.js" type="text/javascript"></script>
    <script src="js/send_message.js" type="text/javascript"></script>


<?php

require_once("models/config.php");
if (!securePage($_SERVER['PHP_SELF'])){die();}
require_once("models/header.php");

echo "
<body>
<div id='wrapper'>
<div id='top'><div id='logo'></div></div>
<div id='content'>


<div id='left-nav'>";
include("left-nav.php");

echo "
</div>
<div id='main'>

<div class='chatBox'>
    <div class='user'>
<input type='text' size='13px' name='username' id='username' value='$loggedInUser->displayname' readonly='readonly' style='border:hidden'/>        

        
    </div>
    
    <div class='main'>

    </div>

    <div class='information'>
Enter Text Below:

    </div>

    <div class='messageBox'>
    
    <form name ='newMessage' id='newmessage' class='newMessage' action='' onclick=''>

        <div class='left'>

            <input type='text' id='message' class='message'  maxlength='100' name='message' />
    
        </div>
        
        <div class='smiley'>

            <input type='button' value = 'Smilies' id='insertSmilies' onclick='open_pop()' />

        </div
        
        ><div class='right'>

            <input type='submit' id='newMessageSend' value='Send' /><span id='nomessage'>No message was entered.</span>

        </div>
        </form>
</div>

</div>
<div id='bottom'></div>
</div>
</body>
</html>";

?>
Config.php on line 123 is where the session starts:

Code: Select all

<?php
if(!isset($language)) $language = "models/languages/en.php";

//Pages to require
require_once($language);
require_once("class.mail.php");
require_once("class.user.php");
require_once("class.newuser.php");
require_once("funcs.php");

session_start();

//Global User Object Var
//loggedInUser can be used globally if constructed
if(isset($_SESSION["userCakeUser"]) && is_object($_SESSION["userCakeUser"]))
{
    $loggedInUser = $_SESSION["userCakeUser"];
}

Re: Session Starts Error

Posted: Wed Sep 25, 2013 5:45 am
by Winawer
It's the same issue you had with your redirect. Session_start() tries to modify headers you've already sent.

Re: Session Starts Error

Posted: Wed Sep 25, 2013 9:26 am
by vitinho444
For this to work your files that require session MUST START FROM:

Code: Select all

<?php
session_start();

Re: Session Starts Error

Posted: Wed Sep 25, 2013 12:45 pm
by Epiales
well, for the life of me, I can't figure out why. I guess I can turn error reporting off, as it's not interfering with anything that I can tell :evil: :evil:

Re: Session Starts Error

Posted: Wed Sep 25, 2013 1:16 pm
by vitinho444
did you did what i just said?

If you did then it needs to work...

YOU NEED TO BE 100% SURE THAT THE FIRST PAGE THAT THE WEBSITE LOADS STARTS WITH THAT CODE.

I had <!DOCTYPE html> before and it screwed everything.

Re: Session Starts Error

Posted: Wed Sep 25, 2013 9:22 pm
by Epiales
vitinho444 wrote:did you did what i just said?

If you did then it needs to work...

YOU NEED TO BE 100% SURE THAT THE FIRST PAGE THAT THE WEBSITE LOADS STARTS WITH THAT CODE.

I had <!DOCTYPE html> before and it screwed everything.
Got it! TYTYTY lol. Amazing how one little thing can be so important :lol: :lol:

Re: Session Starts Error [Resolved]

Posted: Wed Sep 25, 2013 10:03 pm
by vitinho444
Yeah ikr.. Doctype html above all should be number #1 so the browser knows wtf we will write but NOOO PHP IS SELFISH XD

Re: Session Starts Error [Resolved]

Posted: Thu Sep 26, 2013 5:58 am
by Winawer
Of course HTTP headers must be sent before HTML. This is not a PHP limitation.