oo that does look a lot more efficient thanks, but i'm getting this error message when I try it.
Fatal error: Call to undefined function: file_put_contents() in /hsphere/local/home/crazychr/bluewalrus.net/hitter/hit.php on line 14
oo that does look a lot more efficient thanks, but i'm getting this error message when I try it.
Fatal error: Call to undefined function: file_put_contents() in /hsphere/local/home/crazychr/bluewalrus.net/hitter/hit.php on line 14
That means that you're still running PHP4. PHP5 has been out for five years now: upgrade, tell your host to upgrade, or else switch hosts.
In the meantime, here's a replacement (but it only supports the first two arguments):However, note that this doesn't help much against most of the problems there (and will still cause the script to break if the log file gets particularly big). For something like this you really want to use perhaps a small SQLite database.Code:if (!function_exists('file_put_contents')) { function file_put_contents($fn, $data) { $f = fopen($fn, 'w'); fwrite($f, $data); fclose($f); } }
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Okay I have it working now but a terrible way and with the date formatting even sloppier than before. I can't switch to php 5 because my server will make me cancel my other accounts and resign up. They said to could take 2 weeks to do this. So I'm trying it my moderately? poorly coded way.
This works
This brings upPHP Code:$date1 = date('Hi');
$date2 = date('mjy');
Warning: preg_match(): Unknown modifier 'j' in /hsphere/local/home/crazychr/bluewalrus.net/hitter/hit.php on line 20And this bring up thisPHP Code:date1 = date('H\:i');
$date2 = date('m\/j\/y');
Warning: preg_match(): Unknown modifier '2' in /hsphere/local/home/crazychr/bluewalrus.net/hitter/hit.php on line 20I was thinking I needed to clear out the : and / so I tried those other two ways but with no luck. I didn't change the code to the formatting you suggested twey because I and the users of this only use the crazy american date formating and for the first 12 days of the month it could be confusing to look at.PHP Code:$date1 = date('H/:i');
$date2 = date('m\/j\/y');
The whole code as I have it working....
Thanks for anymore help you can offer.PHP Code:<?php
$user = $_SERVER['REMOTE_ADDR'];
$computer = $_SERVER["HTTP_USER_AGENT"];
//To Change the date formate from MM/DD/YY HH:MM go here http://www.php.net/date
$date1 = date('Hi');
$date2 = date('mjy');
$count = "hit.txt";
$value2 = fopen($count, "r+");
$entervalue = fread($value2, 999999999);
$entervalue = $entervalue + 1;
fclose($value2);
$value = fopen($count, "w+");
fwrite($value, $entervalue);
fclose($value);
$hitsfile = "log.txt";
$gethits = fopen($hitsfile, "a+");
$check = fread($gethits, 9999999999);
$page = $entervalue . ". " . $date1 . $date2 . " " . $user . " " . $computer . "\n";
//REMOVE ALL OF THIS IF YOU DON'T CARE IF A USER HAS BEEN HERE MORE THAN ONCE IN A DAY. IF YOU WANT TO BE MORE SPECIFIC TO IF THEY HAVE EVER BEEN THERE. REMOVE "$date . " " ." If you
$beenhere = preg_match("/".$date2."/", $check);
$beenhere2 = preg_match("/".$user."/", $check);
if ($beenhere) {
if ($beenhere2) {
$entervalue = $entervalue - 1;
$value = fopen($count, "w+");
fwrite($value, $entervalue);
fclose($value);
die ("You've been here today.");
}
}
else {
//REMOVE UNTIL HERE
fwrite($gethits, $page);
fclose($gethits);
}
?>
Okay I'm trying to redo it again and I think this new way is more efficient except for the text file size problem anyway. Thanks for any more help you can offer here. I tried making the viewer check if the visitor has been there in the past 10 minutes rather than the day also.
PHP Code:<?php
$user = $_SERVER['REMOTE_ADDR'];
$computer = $_SERVER["HTTP_USER_AGENT"];
//To Change the date formate from MM/DD/YY HH:MM go here http://www.php.net/date
$day = date('z');
$year = date('Y');
$hour = date('H');
$seconds = date('s');
$minutes = date('i');
$minutes = $minutes * 60;
$hour = $hour * 3600;
$time = $hour + $minutes + $seconds;
$date1 = date('H:i');
$date2 = date('m.j.y');
$hitsfile = "log.txt";
$gethits = fopen($hitsfile, "a+");
$check = fread($gethits, 9999999999);
fclose($gethits);
if ($check =< $time + 600 . " " . $user ) {
$count = "hit.txt";
$value2 = fopen($count, "r+");
$entervalue = fread($value2, 999999999);
fclose($value2);
echo "<div id=\"counter\">" . $entervalue . "</div>\n</div></div></html>";
die ;
}
else {
$hitsfile = "log.txt";
$entervalue = $entervalue + 1;
$count = "hit.txt";
$value = fopen($count, "w+");
fwrite($value, $entervalue);
fclose($value);
$page = $entervalue . ". " . $date1 ." " . $date2 . " " . $computer . " " . $time . " " . $user . "\n";
$gethits = fopen($hitsfile, "a+");
fwrite($gethits, $page);
fclose($gethits);
}
?>
Bookmarks