canadezo Posted June 6, 2011 Share Posted June 6, 2011 How can you use IP validation saved from a text file? Here's an example of what I'm trying to do... <?php if IP 'InternetProtocal.txt' , then it script allows to view the page; else show message like "you don't have permision to view this page"; ?> I do understand that above will not work; it's just so you can get an idea of my goal... Link to comment https://forums.phpfreaks.com/topic/238528-ip-and-php-help/ Share on other sites More sharing options...
zer0day Posted June 6, 2011 Share Posted June 6, 2011 $i = 0; $ip = $_SERVER['REMOTE_ADDR']; $file = fopen('InternetProtocol.txt', 'r'); while(!feof($file)) { if(fgets($file) == $ip) { $i = 1; } } if($i == 1) { echo "You may view this page."; } else { echo "You may not view this page..."; } fclose($file); Link to comment https://forums.phpfreaks.com/topic/238528-ip-and-php-help/#findComment-1225786 Share on other sites More sharing options...
WebStyles Posted June 6, 2011 Share Posted June 6, 2011 I'm assuming InternetProtocal.txt has a list of valid ip's and that they are seperated by a semicolon ( so, first you need to read that file and put all the addresses in an array $file =file_get_contents('InternetProtocal.txt'); $ips_on_file = explode(";",$file); next, grab the clients IP address and check to see if it exists in you list: $client_ip = $_SERVER['REMOTE_ADDR']; if(in_array($client_ip,$ips_on_file)){ // OK TO PROCEED }else{ // NO ACCESS } Hope this helps Link to comment https://forums.phpfreaks.com/topic/238528-ip-and-php-help/#findComment-1225787 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.