Jump to content

IP and PHP Help


canadezo

Recommended Posts

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

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

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.