I'm using this script to do 2 things..
- restrict access to specific IP addresses
- connect to my mysql database.
<?php
$ips = array('192.168.100.50','192.168.100.51','::ffff:127.0.0.1');
foreach ($ips as $key) {
if ($_SERVER['REMOTE_ADDR'] == $key) {
$hostName = "localhost";
$userName = "admin";
$password = "password";
$dbName = "test";
mysql_connect($hostName, $userName, $password) or die("Unable to connect to host $hostName");
mysql_select_db($dbName) or die("Unable to select database $dbName");
}
}
?>
This page is called by all the other pages.. and works well.
If the IP is in the $ips array then the pages load fine, the mysql connects and all is well..
If they don't match the page still loads and gives mysql errors rendering it useless.
What I would prefer is if the IP Address isn't in the $ips array then the user is redirected to another web page /site (google)
Any ideas ? Thanks 🙂