arrays - unique ip visit redirect in php without mysql -


i'm sorry if request seems silly . i've looked long time no luck. i'm trying : want when visitor visits link'http:/ /mysite. com/redirect .php' , php script gets ip address, checks if exists in array of ips stored in file 'hits.txt', if redirect him page say'google.com' if doesn't store ip address in file redirect him page 'yahoo.com'. later when comes visit again gets redirected google.com. ofcourse purpose make unique ip visits script. if have idea how without database , sql i'll grateful, if u think can done sql please suggest me easiest way. code far doesn't work :

<?php // unique hits php script // ----------- march 2004 // contact author: uniquehits@sizzly.com  $log = 'hits.txt';  $ip = getenv (remote_addr); $add = true; $hits = 0;  if (!file_exists ($log)) {     echo "error: $log not exist.";     exit; }  $h = fopen ($log, 'r');        if (in_array($ip, array($h))){           header("location: http://google.com");     }         else{       $fp = fopen('hits.txt', 'a');         fwrite($fp, "'" ); fwrite($fp, $ip ); fwrite($fp, "'" ); fwrite($fp, ',' ); fclose($fp);           header("location: http://yahoo.com");          }      fclose($h); ?> 

appreciated , thankful guys .

you use cookies this. it's more reliable way using ip adress, since lot of people have dynamic ip anyway.

http://php.net/manual/en/features.cookies.php


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -