Jump to content

Could someone please help me?


Reaper0167

Recommended Posts

I can't get this to function properly. It gets the ip address, it the ip is a certain ip, it does not add it to the counter and displays the same count, otherwise add it to the counter and display it. With the code below, it just displays "0 times"

<?php
session_start();
$ip=$_SERVER['REMOTE_ADDR'];
if ($ip != '184.59.170.237')
{
$guy = fopen('counterlog.txt', r);
$dog = fread($guy, filesize('counterlog.txt'));
echo 'This site has been visited&nbsp' . $dog+1 . ' times.';
fclose($guy);
$guy = fopen('counterlog.txt', w);
fwrite($guy, $dog+1);
}
else
{
$guy = fopen('counterlog.txt', w);
fwrite($guy, 1);
echo 'This site has been visited&nbsp' . $dog+0 . ' times.';
fclose($guy);
}
?>

This seems to not work properly

Link to comment
https://forums.phpfreaks.com/topic/193849-could-someone-please-help-me/
Share on other sites

Look at this code and compare it to yours.

session_start();
$log_file='counterlog.txt';
$ip=$_SERVER['REMOTE_ADDR'];
if ($ip != '184.59.170.237')
{
$dog = file_get_contents("$log_file");
$doggy=$dog+1;
echo "This site has been visited $doggy times.";
file_put_contents("$log_file", $doggy);
}
else
{
$dog = file_get_contents("$log_file");
echo "This site has been visited $dog times.";
}

 

 

HTH

Teamatomic

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.