Reputation: 27
Well, I have made a portal made for my client and it is all coded in custom php. Now Client have told me to make it only accessible to two IP that is to be used within the company intranet.
well we have a shared hosting for that portal. Is is possible to make it accessible to one ip only ?
and how ? like if there is any code to be added?
Regards
Upvotes: 0
Views: 119
Reputation: 1260
While PHP is pretty cool, why not leave security to things actually designed for security? Create a .htaccess file and put...
order deny,allow
deny from all
allow from xxx.xxx.xxx.xxx
allow from xxx.xxx.xxx.xxx
Where xxx = the IPs you want to allow
Upvotes: 0
Reputation: 665
There are ways to whitelist IP's from inside your webhost cPanel.. If you wanted to do this with PHP, you would need to add this before anything else initiates in your PHP.
$whitelist = array('192.0.0.1', '192.0.0.2', etc);
if(!in_array($_SERVER['REMOTE_ADDR'], $whitelist)){
header('location:http://google.com');
}
Upvotes: 1
Reputation: 192
You have to use the $_SERVER global variable, like this:
if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1') {
// restrict
}
Good alternative is the session filter: http://php.net/manual/en/session.examples.basic.php
You can also use cookies: http://www.php.net/manual/en/function.setcookie.php
Upvotes: 1