FocuSoft Posted October 18, 2013 Share Posted October 18, 2013 Hello, I have this code: <?php $dateTime = date('Y/m/d G:i:s'); $fp = fopen('log.txt', 'r+'); if(!$fp){ echo "Log file doesn't exists."; } else{ $visited = FALSE; while (!feof($fp)) { $buffer = fgets($fp); list ($ip, $time) = split(' ', $buffer); //Checks if IP is already logged. if ($_SERVER['REMOTE_ADDR'] == trim($ip)){ $visited = TRUE; echo "Not your first visit."; } } if (!$visited){ fwrite($fp, $_SERVER['REMOTE_ADDR']. " $dateTime\n"); echo "First visit."; } fclose($fp); } ?> This log ip of visitors, and if is first visit will show us "First visit.", if is not the first visit will show us "Not your first visit." Now I want to do some modifications to this code, I want to redirect visitors if is not the first visit, and if is the first visit to show a newsletter.html page I think is simple, but I'm not a PHP coder and I don't know how to do it. Thanks in advance for help. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 18, 2013 Share Posted October 18, 2013 Change $visited = TRUE; echo "Not your first visit."; to header('Location: http://site.com/new-location-here'); exit; Quote Link to comment Share on other sites More sharing options...
adoado Posted October 18, 2013 Share Posted October 18, 2013 Checking IPs is not a reliable method (see NAT/PAT http://en.wikipedia.org/wiki/Network_address_translation). If they are identifiable because they are logging in, you can persist it in a database of some sort, or use client side cookies. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.