Session Starts Error [Resolved]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Session Starts Error [Resolved]

Post 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"];
}
Last edited by Epiales on Wed Sep 25, 2013 9:22 pm, edited 1 time in total.
Nothing fancy, but a work in progress!

http://gameplaytoday.net
Winawer
Posts: 180
Joined: Wed Aug 17, 2011 5:53 am

Re: Session Starts Error

Post by Winawer »

It's the same issue you had with your redirect. Session_start() tries to modify headers you've already sent.
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: Session Starts Error

Post by vitinho444 »

For this to work your files that require session MUST START FROM:

Code: Select all

<?php
session_start();
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Session Starts Error

Post 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:
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: Session Starts Error

Post 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.
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
User avatar
Epiales
Posts: 1119
Joined: Thu Aug 15, 2013 1:38 am

Re: Session Starts Error

Post 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:
Nothing fancy, but a work in progress!

http://gameplaytoday.net
User avatar
vitinho444
Posts: 2819
Joined: Mon Mar 21, 2011 4:54 pm

Re: Session Starts Error [Resolved]

Post 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
My Company Website: http://www.oryzhon.com

Skype: vpegas1234
Winawer
Posts: 180
Joined: Wed Aug 17, 2011 5:53 am

Re: Session Starts Error [Resolved]

Post by Winawer »

Of course HTTP headers must be sent before HTML. This is not a PHP limitation.
Post Reply

Return to “Beginner Help and Support”