...

View Full Version : Header Problems



Jesuspwnt
12-27-2007, 12:06 AM
Right again with the shoutbox problems :P..

I have written some spam protection code
and this is the last of it:


if(!$spam){
setcookie("shoutbox", "11211111511610110033", time()+$total_secs);
$insert = mysql_query("INSERT INTO `[column]`.`[table]` (`id` ,`message` ,`author` ,`time` ,`ip`) VALUES (NULL, '{$message}', '{$user}', '{$shoutbox_date}', '{$ip}')");
if(!$insert){
echo "Could Not Post Shout";
}


but im getting this error:

Warning: Cannot modify header information - headers already sent by (output started at [PATH]/top.php:2) in [path]shoutbox.php on line 38

line 38 is the setcookie.

Whats wrong with it? :s

Inigoesdr
12-27-2007, 12:19 AM
On line 2 of top.php you're outputting something. Post top.php if you want specific help, but to avoid the error you're going to have to change it so it doesn't output anything or use output buffering.

Jesuspwnt
12-27-2007, 12:20 AM
top.php, line 2:
echo "<html>\n <head>\n <title>".$site['name']."</title>\n";

Inigoesdr
12-27-2007, 12:24 AM
Yeah, you can't echo/print/output anything before you set headers or cookies(because cookies use headers). You should be doing all of the processing and cookie setting before you display the page, but you can use ob_start() (http://php.net/ob_start) at the top of your page and ob_end_flush() (http://php.net/ob_end_flush) at the bottom to avoid the headers already sent error by buffering all output until the page is fully generated.

Jesuspwnt
12-27-2007, 01:03 AM
still doesn't work with ob_start() and ob_end_flush();

Inigoesdr
12-27-2007, 04:30 AM
Post the code you're using.

Jesuspwnt
12-27-2007, 11:42 AM
<?php
// File: /includes/panels/shoutbox_panel/shoutbox.php

ob_start();
$short_date = date("d/m/Y H:i");
$user = $_SESSION['username'];
$ip = $_SERVER['REMOTE_ADDR'];
$shoutbox_date = $short_date.":".date("s");
$flood_time = mysql_result(mysql_query("SELECT [field] FROM [column] WHERE id='1'"), 0);

$time = explode(":", $flood_time);
$h = str_replace("h", "", $time[0]);
$m = str_replace("m", "", $time[1]);
$s = str_replace("s", "", $time[2]);

$total_secs = "";
if($h != ""){
$total_secs = $total_secs+($h*60*60);
}
if($m != ""){
$total_secs = $total_secs+($m*60);
}
if($s != ""){
$total_secs = $total_secs+($s);
}

if(isset($_SESSION['username'])){
echo "<form method=\"post\" name=\"shoutbox\">\n<br />\n<textarea name=\"message\" class=\"shoutbox_ta\"></textarea>\n<br /><input type=\"submit\" value=\"Shout!\" name=\"shout_submit\"></form>";
if(isset($_POST['shout_submit'])){
if(isset($_POST['message'])){
$message = trim(htmlentities($_POST['message']));
if($message == ""){
echo "You Must Include Alpha Numeric Characters In Your Post for it to become valid";
$spam=1;
}
if($_COOKIE['shoutbox'] == "11211111511610110033"){
$spam=1;
echo "Leave ".$total_secs." seconds Between Each Of Your Shouts";
}
if(!$spam){
setcookie("shoutbox", "11211111511610110033", time()+$total_secs);
$insert = mysql_query("INSERT INTO `[db]`.`[column]` (`id` ,`message` ,`author` ,`time` ,`ip`) VALUES (NULL, '{$message}', '{$user}', '{$shoutbox_date}', '{$ip}')");
if(!$insert){
echo "Could Not Post Shout";
}
}
}
}
echo "<hr width=\"100%\" color=\"#00ff00\">";
}

$shouts = mysql_query("SELECT * FROM shoutbox ORDER BY id DESC LIMIT 0,5");
echo " <table>\n";
while($shout = mysql_fetch_array($shouts)){
echo " <tr>\n <td>\n <b>".$shout['author']."</b>\n";
if(isset($_SESSION['auth']) && $_SESSION['auth'] >= 103){
echo "[<font color=red><a href=\"/[admin panel]/shoutbox.php?action=delete&id=".$shout['id']."\">x</a></font>]";
}
echo "<br />".substr($shout['time'], 0, -3);
echo "\n <br />".$shout['message'];
if($_SESSION['auth'] > 102){
echo "<br />".$shout['ip'];
}
echo "\n </td>\n </tr>\n";
}
echo " </table>";
ob_end_flush();
?>

anarchy3200
12-27-2007, 12:20 PM
In that code i dont see where you include top.php?

The ob_start needs to be before you start outputting things, i.e. at least before the echo in top.php.

Its best if you place it at the very top of your page so take into account any includes you make and confirm that all of them are after the ob_start.

Jesuspwnt
12-27-2007, 12:29 PM
the reason you don't see the script including top.php is because shoutbox.php is also an included page...

Edit:
YAY FIXED!!! WOOP WOOP



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum