PHP amateur and enthusiast here. I'm hoping you can help with a simple script.
What I want to do is check the IP address of my site's visitor, and if it is equal to a specific IP (e.g. 127.0.0.1), then I want it to echo a link (maybe contained in a variable) and, if it is not equal to that specific IP, then I want to echo another link.
I got hold of a relevant script that checks the IP address of the visitor and echoes it. But where I'm having the most difficulty is checking / comparing the visitor's IP with my pre-determined IP.
Here's the code I got:
- Code: Select all
<html>
<head>
<title>What is my IP address?</title>
</head>
<body>
<?php
if (getenv(HTTP_X_FORWARDED_FOR)) {
$pipaddress = getenv(HTTP_X_FORWARDED_FOR);
$ipaddress = getenv(REMOTE_ADDR);
echo "Your Proxy IPaddress is : ".$pipaddress. "(via $ipaddress)" ;
} else {
$ipaddress = getenv(REMOTE_ADDR);
echo "Your IP address is : $ipaddress";
}
?>
</body>
</html>
I have also found this script to compare a range of IPs
- Code: Select all
<?php
// IP Range: 192.168.0.1 - 192.168.12.255
// Provided IP: 192.168.11.196
$IPStart = explode(".", "192.168.0.1");
$IPFinish = explode(".", "192.168.12.254");
$IPProv = explode(".", "192.168.11.196");
$Between = true;
for($i = 0; $i < 4; $i++) {
if($IPStart[$i] > $IPProv[$i] || $IPFinish[$i] < $IPProv[$i]) {
$Between = false;
}
}
if($Between !== false) {
echo "Match";
} else {
echo "No Match!";
}
?>
If you can please help that would be awesome



