Jump to content

Check if line in txt exists


raiyen90

Recommended Posts

Ok so i have a hit counter on my site, but the problem is people going and reloading the page over and over, so i need to make it so it grabs their ip and sends that to a seperate text file. Thats easy but i cannot find anything on searching lines of a text file for a certain string. sooooo if u could help me?? maybe

 

thanx

Link to comment
https://forums.phpfreaks.com/topic/55983-check-if-line-in-txt-exists/
Share on other sites

ok

<?php 
$filename = "hits.txt"; 
$handle = fopen($filename, "r");
$views = fread($handle, filesize($filename));
fclose($handle); 
$handle = fopen($filename, "w"); 
$views++; 
fwrite($handle, $views); 
fclose($handle); 
echo $views; 
php?>

 

there is my code i have currently, i want it to check if the ip address exists in any lines of a txt file, if not grab the ip and save it to a text file (on a new line of course). But if the ip does exist to just skip the whole code of my counter where it writes the number to my hits.txt

 

hope that sounds better?

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.