Header not sent

Started on the old forum in February 2011 · view the original in the archive · old links redirect here

12 replies · 598 views · started 15 years ago · 1 min read

4 participants
whitewingz Developer · 64 posts #1
<?php
session_name("PHPSESSID");
session_start();
include("iconfig.php");
include("icore.php");

echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>";
echo "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\"\"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">";
echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">";

echo "<link rel=\"shortcut icon\" href=\"pgsm.ico\" type=\"image/x-icon\" />";
echo "<link rel=\"StyleSheet\" type=\"text/css\" href=\"whitestyle.css\" />";
echo "<meta http-equiv=\"Cache-Control\" content=\"must-revalidate\" />
<meta http-equiv=\"Cache-Control\" content=\"no-cache\"/>
<meta name=\"description\" content=\"PinoyTrix\"/>
<meta name=\"keywords\" content=\"free, community, forums, chat, wap, communicate\"/></head>";
echo "<body>";

connectdb();
$bcon = connectdb();
if (!$bcon)
{

echo "<div align=\"center\"><div class=\"t2\">Error.!</div><br/>";
echo "Cant connect to database<br/>";
echo "This error happens usually when backing up the database, please be patient, The site will be up any minute<br/>";
echo "Thank You Very Much<br/><a href=\"index.php\">Home</a><br/><div class=\"foot\">$mysite</div></div>";
echo "<br/>Page Took ";
$load = microtime();
print (number_format($load,2));
echo " Seconds";
echo "</div>";
echo "</body>";
echo "</html>";
exit();
}
$nick = safe(cleanInput($_GET["u"]));
$pwd = safe(cleanInput($_GET["p"]));
$myid = getuid_name($nick);
$whitestyle = mysql_fetch_array(mysql_query("SELECT mystyle FROM ibwf_users WHERE id='".$myid."'"));
$user = mysql_fetch_array(mysql_query("SELECT name FROM ibwf_users WHERE id='".$myid."'"));
$ubrowser = safe($_SERVER['HTTP_USER_AGENT']);
$uipadd = getip();

$tolog = false;
echo "<title>$user[0]-$toptitle*</title>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$whitestyle[0]\"/>";
echo "</head>";
echo "";

$uinf = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_users WHERE myname='".$nick."'"));
if($uinf[0]==0)
{
$brws = explode(" ",$HTTP_USER_AGENT);
	$ubr = $brws[0];
	$ip = $_SERVER['REMOTE_ADDR'];
//Check for user ID
echo "<div class=\"notice\"><div class=\"mid\"><b>PinoyTrix</b></div><div class=\"error\">Error.!!<br/>User Does Not Exist Or Not Yet Registered<br/><a href=\"terms.php\">Register It Now</a><br/></div>";
}else{
//check for pwd
$epwd = md5($pwd);
$uinf = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_users WHERE username='".$user."' AND password='".$epwd."'"));
if($uinf[0]==0)
{
echo "<div class=\"notice\"><div class=\"mid\"><b>PinoyTrix</b></div><div class=\"error\">Error.!!<br/>Are You Trying To Guess Your Password Or What?<br/>If you forgot your own password<br/>just retrieve it <a href=\"forgotpw.php\">HERE</a><br/></div>";
}else{
$logedin = mysql_fetch_array(mysql_query("SELECT uid FROM ibwf_ses WHERE uid='".$myid."'"));
//i altered the if statement here to //accomodate more login attempt and //by that you can access it always. //.Remod by escape_string
if($logedin[0]=='100')
{
mysql_query("DELETE FROM ibwf_ses WHERE uid='".$myid."'");
}else{
[B]header("location:index.php?do=main");[/B]
$rndsid = rand(111111111,999999999);

      $tm = (time() - $timeadjust) ;
      $xtm = $tm + (getsxtm()*60);
      $did = $uid.$tm;
$res = mysql_query("INSERT INTOibwf_ses SET id='".md5($did)."', uid='".$myid."', expiretm='".$xtm."'");
if($res)
{
$tolog=true;

$New_Time = (time() + $timeadjust);
$show_date=date("l, d F Y",$New_Time);
$show_time=date("g:ia",$New_Time);
$Hour=date("G",$New_Time);
$_SESSION['sid'] = md5($did);

$lact = mysql_fetch_array(mysql_query("SELECT lastact FROM ibwf_users WHERE id='".$myid."'"));
$lst = $lact[0];
mysql_query("UPDATE ibwf_users SET lastvst='".$lst."', lastact='".time()."', browserm='".$ubrowser."', ipadd='".$uipadd."' WHERE id='".$myid."'");
}
}
}
}

if($tolog)
{

}else{

}
exit();
?>
</html>

guyz i have problem with header it's not sent to location what's my problem here?

if($logedin[0]=='100')
{
mysql_query("DELETE FROM ibwf_ses WHERE uid='".$myid."'");
}else{
[B]header("location:index.php?do=main");[/B]
$rndsid = rand(111111111,999999999);

      $tm = (time() - $timeadjust) ;
      $xtm = $tm + (getsxtm()*60);
      $did = $uid.$tm;
$res = mysql_query("INSERT INTOibwf_ses SET id='".md5($did)."', uid='".$myid."', expiretm='".$xtm."'");
if($res)
{
$tolog=true;

$New_Time = (time() + $timeadjust);
$show_date=date("l, d F Y",$New_Time);
$show_time=date("g:ia",$New_Time);
$Hour=date("G",$New_Time);
$_SESSION['sid'] = md5($did);

$lact = mysql_fetch_array(mysql_query("SELECT lastact FROM ibwf_users WHERE id='".$myid."'"));
$lst = $lact[0];
mysql_query("UPDATE ibwf_users SET lastvst='".$lst."', lastact='".time()."', browserm='".$ubrowser."', ipadd='".$uipadd."' WHERE id='".$myid."'");
}
}
}
}

thanks for the help

frostymarvelous Senior · 266 posts #2

Try making the location Location. Caps L. Headers are case sensitive, but sometimes they work.

Perfection comes at a cost

I accept liberty!

arnage Lead · 811 posts #4
 [ B ] header("location:index.php?do=main");[ / B ]

Remove

[ B ] and [ / B ].
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
whitewingz Developer · 64 posts #5

Sorry, are not really there i thought it will be bold even if in php bbcode, i do that so u can see easyly,

arnage Lead · 811 posts #6

Aha, upss. 🙂 Try like this:

if($logedin[0]=='100') 
{ 
mysql_query("DELETE FROM ibwf_ses WHERE uid='".$myid."'"); 
}else{ 
$rndsid = rand(111111111,999999999); 

      $tm = (time() - $timeadjust) ; 
      $xtm = $tm + (getsxtm()*60); 
      $did = $uid.$tm; 
$res = mysql_query("INSERT INTOibwf_ses SET id='".md5($did)."', uid='".$myid."', expiretm='".$xtm."'"); 
if($res) 
{ 
$tolog=true; 

$New_Time = (time() + $timeadjust); 
$show_date=date("l, d F Y",$New_Time); 
$show_time=date("g:ia",$New_Time); 
$Hour=date("G",$New_Time); 
$_SESSION['sid'] = md5($did); 

$lact = mysql_fetch_array(mysql_query("SELECT lastact FROM ibwf_users WHERE id='".$myid."'")); 
$lst = $lact[0]; 
mysql_query("UPDATE ibwf_users SET lastvst='".$lst."', lastact='".time()."', browserm='".$ubrowser."', ipadd='".$uipadd."' WHERE id='".$myid."'"); 
} 
header("location:index.php?do=main"); exit;
} 
} 
} 
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***
whitewingz Developer · 64 posts #7

arnage wrote: Aha, upss. 🙂 Try like this:

if($logedin[0]=='100') 
{ 
mysql_query("DELETE FROM ibwf_ses WHERE uid='".$myid."'"); 
}else{ 
$rndsid = rand(111111111,999999999); 

      $tm = (time() - $timeadjust) ; 
      $xtm = $tm + (getsxtm()*60); 
      $did = $uid.$tm; 
$res = mysql_query("INSERT INTOibwf_ses SET id='".md5($did)."', uid='".$myid."', expiretm='".$xtm."'"); 
if($res) 
{ 
$tolog=true; 

$New_Time = (time() + $timeadjust); 
$show_date=date("l, d F Y",$New_Time); 
$show_time=date("g:ia",$New_Time); 
$Hour=date("G",$New_Time); 
$_SESSION['sid'] = md5($did); 

$lact = mysql_fetch_array(mysql_query("SELECT lastact FROM ibwf_users WHERE id='".$myid."'")); 
$lst = $lact[0]; 
mysql_query("UPDATE ibwf_users SET lastvst='".$lst."', lastact='".time()."', browserm='".$ubrowser."', ipadd='".$uipadd."' WHERE id='".$myid."'"); 
} 
header("location:index.php?do=main"); exit;
} 
} 
} 

still n0t w0rking..

frostymarvelous Senior · 266 posts #10

I just looked at your code properly. You echoed some xml at the top. Will cause headers to be already sent. If you have warnings on, you will see an error. If you need the output before the header, take a look at php output buffering. Google ob_start()

It seems it is html not xml only. Every echo statement, whitespace etc will count as output and cause headers to be sent.

Perfection comes at a cost

I accept liberty!

whitewingz Developer · 64 posts #11

frostymarvelous wrote: I just looked at your code properly. You echoed some xml at the top. Will cause headers to be already sent. If you have warnings on, you will see an error. If you need the output before the header, take a look at php output buffering. Google ob_start()

It seems it is html not xml only. Every echo statement, whitespace etc will count as output and cause headers to be sent.

thanks for the idea.. and also thanks to all who help me about my problem.. i solve my problem using this..

ob_start();

echo "Some content"; header('X-Example-Header: foo'); echo "Some more content";

$output = ob_get_contents(); ob_end_clean();

echo $output;

frostymarvelous Senior · 266 posts #12

If you ever need to send headers after output has been sent, use this. But use it sparingly since calling ob_start allocates 40kb of memory to the script with 10kb increments. Your application can run out of memory real fast.

There are two ways out. Make all your login checks, header stuff and session starts before you start outputting any data to the browser.

The best thing is to use a templating system with which you can format the output to suit the user.

Also, you can store your output in a string and echo it at the end of all your checks.

Perfection comes at a cost

I accept liberty!

whitewingz Developer · 64 posts #13

better if you use this to check if headers already sent..

if(headers_sent($file, $line)){ // ... where were the mysterious headers sent from? echo "Headers were already sent in $file on line $line..."; } header("location:index.php?do=main");

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close