Problem with headers again...

drenferalis

New Member
Messages
5
Reaction score
0
Points
0
I have a page that has a login and for some reason the login isnt posting becuase of my css header. Heres the information:


Login Page
PHP:
<?php


require_once('db.php');
include('functions.php');
include('settings.php');
    if (array_key_exists('_submit_check', $_POST))
    {$_POST=htmlentitiesarray($_POST);
        if ( $_POST['username'] != '' && $_POST['password'] != '' )
        {
            $query = mysql_query ( 'hidden' );


            if ( mysql_num_rows($query) == 1 )
            {
                $row = mysql_fetch_assoc ( $query );
if ( $row['Level_access'] == 5){
                    $error = 'You are banned!.';
                }elseif ( $row['Level_access'] == 4){
                    $error = 'Site is down for maintenance.';
                }
elseif ( $row['Active'] == 1 )
                {
                    session_start();
                    if($row['Level_access'] == 6 or $row['Level_access'] == 7){$_SESSION['modstats'] = 1;}
                    $_SESSION['user_id'] = $row['ID'];
                    $_SESSION['logged_in'] = TRUE;
                    $_SESSION['epoch'] = date("U");
                    header ("Location: charselect.php");
                }
                elseif ( $row['Active'] == 0 ) {
                    $error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';
                }
                elseif ( $row['Active'] == 2 ) {
                    $error = 'You are suspended!';
                }
                
            }
            else {
                $error = 'Login failed!';
            }
        }
        else {
            $error = 'Please use both your username and password to access your account';
        }
    }
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>LegendsRP - Login</title>
    
</head>


<body>
 <center><img src="title.jpg"></center><br><br><center>
    <?php
if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') )
{
   if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Netscape') )
   {
     $browser = 'Netscape (Gecko/Netscape)';
   }
   else if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') )
   {
     $browser = 'Mozilla Firefox (Gecko/Firefox)';
   }
   else
   {
     $browser = 'Mozilla (Gecko/Mozilla)';
   }
}
else if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') )
{
   if ( strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') )
   {
     $browser = 'Opera (MSIE/Opera/Compatible)';
   }
   else
   {
     $browser = 'Internet Explorer (MSIE/Compatible)';
   }
}
else
{
   $browser = 'Others browsers';
}

if($browser == 'Other browsers'){echo "You are using an unsupported browser, you may have problems playing this game.";}
if($browser == 'Mozilla Firefox (Gecko/Firefox)'){echo'<b><font color="red">This site is currently being remodeled for this browser... The game works but may not look right. Please forgive us or use Internet Explorer.</font></b>';}
?>
    
 <div id=frontcontainer style="margin-bottom:12px">
<h3>Game Details</h3><p>To be popular... To be famous... To become history... To become a legend... many people of all sorts try to become these and fall short of the mark from someone better. Well here you can attempt it all over again. But here there is a difference. Here you will work to become the legend of whatever you choose. Best of all there is no one to stop you... Here at Legends RP we focus on making players a part of the headlines. Everyday all of the roleplay is read and the headlines are picked out. As long as you participate you can be one of those legends. You can be popular. You can become a part of the sites history. And best of all. Its FREE. Even as the game is in development you can be a part of its creation. If you think something is missing and you can describe it, we can add it. Just mail the development team at ID 1. Remember, here everyone that participates is a legend. </p></div>

<div id="login">
<div id="err"><?php if(isset($error)){ echo '            <p class="error">' . $error . '</p>' . "\n";}?></div>

        <form class="form" method="post">


            <input type="hidden" name="_submit_check" value="1"/>


            <div style="margin-top:12px; margin-bottom:10px">
                <img src="images/username.gif" alt="username" border="0"/>
                <input class="input" type="text" name="username" id="username" size="25" maxlength="40" value="" />
            </div>
            <div style="margin-bottom:6px">
                <img src="images/password.gif" alt="password" border="0"/>
                <input class="input" type="password" name="password" id="password" size="25" maxlength="32" />


            </div>
            <input type="image" name="Login" value="Login" class="submit-btn" src="images/btn.gif" alt="submit" title="submit" />
            <br class="clear" />
 <a href="register.php"/>Register</a>
        </form>


    </div>
<div id=frontcontainer><h3>Upcoming Events</h3>
<p>These are the following site events:</P>
<ul>
<li>March of '09* - The reopening of the site!</li>
</ul>
*The owner holds no responsibility for the accuracy of this date.
</div>

<div id=fcont2 width=100%><h3>Advert</h3><!-- START ADTOLL.COM CODE V1.0 --><STYLE>A.at_adv_here_13790, A.at_pow_by_13790 {font-family: Arial,Sans-Serif; font-size: 10px; font-style: normal; font-weight: normal; font-variant: normal; text-transform: none; color: #000000; text-decoration: none; }A.at_adv_here_13790:hover, A.at_pow_by_13790:hover { color: #0000FF; text-decoration: underline; }</STYLE><SCRIPT type="text/javascript">adtoll_see_your_ad_here = 1;adtoll_your_text = "Advertise with us cheap!";adtoll_show_powered_by = 1;</SCRIPT><SCRIPT src="http://adserve.adtoll.com/js/at_ag_13790.js" type="text/javascript"></SCRIPT><!-- END ADTOLL.COM CODE V1.0 --></div></center></body>


</html>
Settings Page
PHP:
<?php
if($_SESSION['user_id'] == ''){
header("Location : http://www.legendsrp.com/login.php");
}
    $url         =    'http://www.legendsrp.com/';//full path to the root folder of your login installation (don't foget the trailing slash!)
    $site_email    =    'webrpgdesign@gmail.com';//will be used for emailing
    $domain_name    =    'www.legendsrp.com';//your domain name
$query = "SELECT * FROM users WHERE ID = '".$_SESSION['user_id']."'";
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array( $result );
$tut = $row['tut'];
if($_SESSION['gameid'] == ''){
header("Location : http://www.legendsrp.com/charselect.php");
}
$id = $_SESSION['gameid'];

$query = "SELECT * FROM shops WHERE owner = '".$id."'";
$result = mysql_query($query) or die(mysql_error());

if(mysql_num_rows($result) == 1){$shop = true;}else{$shop = false;}
$query = "SELECT * FROM Characters WHERE Id='".$id."'";


$result = mysql_query($query) or die(mysql_error());


$row = mysql_fetch_array( $result );
if($row['dead'] == 1){Die('This character is dead! <a href=charselect.php>Click here</a> to go back to the character select.');}
$str = $row['Str'];
$def = $row['Def'];
$spd = $row['Spd'];
$int = $row['Int'];
$mp = $row['Mp'];
$hp = $row['HP'];
$itd = $row['Itd'];
$dex = $row['Dex'];
$lvl = $row['Level'];
$uhair = $row['Uhair'];
$map = $row['map'];
$epocage = $row['epocage'];
$_SESSION['css'] = $row['css'];
$istr = $row['iStrength'];
$imag = $row['iMagic'];
$ispd = $row['iSpeed'];
$idex = $row['iDexterity'];
$adult = $row['adult'];
$username= $row['Username'];
$class['value'] = $row['Class'];
$race['value'] = $row['race'];
$gold = $row['Gold'];
$bgold = $row['Banked Gold'];
$stone = $row['Stone'];
$copper = $row['Copper'];
$goldn = $row['GoldN'];
$lid = $row['LID'];
if($lid == '1'){
$locate = 'Home';
};
$party = $row['Party'];
if(!isset($party)){
$party = 'None';
};
$fstat = $row['Stat'];
$ap =$row['AP'];
$taunt = $row['Taunt'];
$result = mysql_query("SELECT * FROM events")
or die(mysql_error());
$row = mysql_fetch_array( $result );


while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row
if($row['ID'] == $id AND $row['Read'] == 0){$evnt = 1;}
}

$result = mysql_query("SELECT * FROM mail")
or die(mysql_error());
$row = mysql_fetch_array( $result );


while($row = mysql_fetch_array( $result )) {
    // Print out the contents of each row
if($row['id'] == $id AND $row['read'] == 0){$mail = 1;}
}
$result = mysql_query("SELECT * FROM classes WHERE value = '".$class['value']."'")
or die(mysql_error());
$row = mysql_fetch_array($result);
$class['name'] = $row['name'];
$class['stage'] = $row['stage'];
$str = $str * $row['strmod'];
$def = $def * $row['defmod'];
$spd = $spd * $row['spdmod'];
$int = $int * $row['intmod'];
$mp =  $mp *  $row['mpmod'];
$mhp =  $mhp *  $row['hpmod'];
$itd = $itd *  $row['itdmod'];
$dex = $dex *  $row['dexmod'];

$result = mysql_query("SELECT * FROM races WHERE ID = '".$race['value']."'")
or die(mysql_error());
$row = mysql_fetch_array($result);
$race['name'] = $row['Name'];
$str = $str * $row['strmod'];
$def = $def * $row['defmod'];
$spd = $spd * $row['spdmod'];
$int = $int * $row['intmod'];
$mp =  $mp *  $row['mpmod'];
$itd = $itd *  $row['itdmod'];
$dex = $dex *  $row['dexmod'];
$mhp = round(($str * 10 + $def * 20) * $lvl);
$mhp =  $mhp *  $row['hpmod'];

$result = mysql_query("SELECT * FROM classes WHERE value = '".$class['value']."'")
or die(mysql_error());
$row = mysql_fetch_array($result);
$mhp =  round($mhp *  $row['hpmod']);

if($hp>$mhp){
$hp=$mhp;
$query = "UPDATE `Characters` SET `HP` =".$hp." WHERE `Id` =".$id." LIMIT 1";
mysql_query($query);
};

$mmp = $int * 5;

if($mp>$mmp){
$mp=$mmp;
$query = "UPDATE `Characters` SET `MP` =".$mp." WHERE `Id` =".$id." LIMIT 1";
mysql_query($query);
};
echo'<link href="css/styles.css" rel="stylesheet" type="text/css" />';
echo'<title>LegendsRP - Game</title>';
?>
Problem Page: www.legendsrp.com/login.php
Login Info:Test
Pass: test

Reply with any help you can please and thanks.
 

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
do this:

settings.php
Code:
ob_start();
echo'<link href="css/styles.css" rel="stylesheet" type="text/css" />';
echo'<title>LegendsRP - Game</title>';

login.php
Code:
session_start();
ob_flush();

the ob_XXXXXX functions cache output so if you accidentally send anything to the output or if you purposefully want to cache the output, you can modify it and then send it when you want.

ob_start() - start buffering
ob_flush() - send buffer to output
 
Last edited:

FengFeng

New Member
Messages
59
Reaction score
0
Points
0
do this:

settings.php
Code:
ob_start();
echo'<link href="css/styles.css" rel="stylesheet" type="text/css" />';
echo'<title>LegendsRP - Game</title>';
login.php
Code:
session_start();
ob_flush();
the ob_XXXXXX functions cache output so if you accidentally send anything to the output or if you purposefully want to cache the output, you can modify it and then send it when you want.

ob_start() - start buffering
ob_flush() - send buffer to output
It's also great help for me
Edit:
But i think the real problem is in the Settings Page.
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/lrp/public_html/legendsrp.com/settings.php:131) in /home/lrp/public_html/legendsrp.com/login.php on line 24
settings.php line 131 ,where is it?what's wrong here?
 
Last edited:

garrettroyce

Community Support
Community Support
Messages
5,609
Reaction score
250
Points
63
Once you echo anything, you implicitly must send the headers. Also, if you have any content outside of the <? ?> tags, that's output. Errors are also output. functions like header() and session_start() require that there has been no output yet.
 

drenferalis

New Member
Messages
5
Reaction score
0
Points
0
This code worked perfectly with my last server so i think its just the switch between php's. Im trying the ob start and flush now
Edit:
FIXED
Thanks everyone!!!!!
 
Last edited:
Top