
August 7th, 2003
08:12 PM
Problem with headers.
I'm making a shoutbox script, that I want people to use. The problem is that I use cookies as one of the anti-spam features.. and of course I'm getting headers already sent when I include the script in a website.
I tried ob_start and ob_end_flush at the start and end of the shoutbox script, but that doesn't work, I would have to put it in the website's layout. But I don't want people to have to do it themselves, it's a pain in the *** to tell people to do all this just to make your script to work.. They never understand :P
So, any suggestions??

August 7th, 2003
08:13 PM
By the way, I don't want them to HAVE to use an iFrame.. I want them to have the choice between an iFrame (where there's no problems with headers) and a simple include();

August 7th, 2003
08:53 PM
with Mr. Jones
Status: Offline!
you could just log the last time ipX made a shout and compare against that. no cookies.
___________________
http://www.philbrodeur.com - Expert PHP Development and Tutorials

August 8th, 2003
12:11 AM

Wow, thanks for the idea. that was some sport!
here's how I did my ip checker..
<?php
function read_log() {
if (!file_exists("iplog.dat")) {
touch("iplog.dat");
chmod("iplog.dat",0666);
$file = fopen("iplog.dat", "w");
fwrite($file, serialize(array(array('',''),array('',''),array('',''),array('',''))));
fclose($file);
}
$lines = file("iplog.dat");
return unserialize($lines[0]);
}
function write_log() {
$userIp = $_SERVER["REMOTE_ADDR"];
$newArray = array($userIp,time());
$array = read_log();
$array[3] = $array[2];
$array[2] = $array[1];
$array[1] = $array[0];
$array[0] = $newArray;
$newIpList = serialize($array);
$file = fopen("iplog.dat", "w");
fwrite($file, $newIpList);
fclose($file);
}
function verif_ip() {
$userIp = $_SERVER["REMOTE_ADDR"];
$array = read_log();
foreach ($array as $thearray) {
if (in_array($userIp,$thearray)) {
if ((time() - $thearray[1]) < 30) {
echo "spam protection.. wait 30 seconds";
return false;
}
else { return true; }
}
else { return true; }
}
}
?>
(maybe someone, someday could get help from this)
Last edited by trunks, August 8th, 2003 12:35 AM (Edited 1 times)

August 8th, 2003
02:33 AM
that's quite long and complex. Mine is a simple array with the keys of the array being the user's IP and the values being the last post time.
like this
$array[ $_SERVER['REMOTE_ADDR'] ] = time ( );
Everytime someone posts, i check if $array[ $_SERVER['REMOTE_ADDR'] ] exists. If it does, i subtract the value from time ( ) and see if it's smaller than $timeout. If it is, then display spamming message. If it doesn't exists or the difference between the time is greater than $timeout. I reset the time. You can do use exactly the same format for users online scripts. $users_online = count ( $array ); Just remember to loop through the array and remove "expired" users before you count ; ).
___________________
http://celerondude.com
Last edited by CDude, August 8th, 2003 02:36 AM (Edited 1 times)

August 8th, 2003
04:28 PM
I thought that adding something to an array was temporary..
Meaning the script will not remember the array if someone else executes the script it would only have his ip and lose the guy before's.. no? that's why I write it in a file.. maybe you could explain more? heh
Last edited by trunks, August 8th, 2003 04:34 PM (Edited 1 times)

August 8th, 2003
04:55 PM
with Mr. Jones
Status: Offline!
serialize() array and store that in the textfile. Then just load textfile, unserialize contents and you have array
___________________
http://www.philbrodeur.com - Expert PHP Development and Tutorials

August 8th, 2003
05:06 PM
yeah, so that's basically what I'm doing..

August 8th, 2003
05:07 PM
with Mr. Jones
Status: Offline!
but you COULD do it in maybe 6 lines...
___________________
http://www.philbrodeur.com - Expert PHP Development and Tutorials

August 8th, 2003
06:01 PM
I don't think I could do it in 6 lines unless I'd want the array to become huge, which I don't.. I only wanna keep it to a few ips logged. What takes space(characters) is the part to cycle the ips..
I do agree that my code is not the smallest code you could have to do this though..