Okay...
I know it is best to place cron scripts outside of the public directory, but it is best suited if it is in the public directory. Now, I know that when cron executes a script, it doesn't have an IP... So, i decided to use the following code...
<?
function iptype1 () {
if (getenv("HTTP_CLIENT_IP")) {
return getenv("HTTP_CLIENT_IP");
} else {
return "none";
}
}
function iptype2 () {
if (getenv("HTTP_X_FORWARDED_FOR")) {
return getenv("HTTP_X_FORWARDED_FOR");
} else {
return "none";
}
}
function iptype3 () {
if (getenv("REMOTE_ADDR")) {
return getenv("REMOTE_ADDR");
} else {
return "none";
}
}
function ip() {
$ip1 = iptype1();
$ip2 = iptype2();
$ip3 = iptype3();
if (isset($ip1) && $ip1 != "none" && $ip1 != "unknown") {
return $ip1;
} else if (isset($ip2) && $ip2 != "none" && $ip2 != "unknown") {
return $ip2;
} else if (isset($ip3) && $ip3 != "none" && $ip3 != "unknown") {
return $ip3;
} else {
return "none";
}
}
$ipaddress = ip();
$cron_address = "";
if ($ipaddress == $cron_address ) {
echo("It works");
} else {
echo("<font color=\"#C00000\"><b>Error: Access Denied</b></font><br>");
echo("We're sorry, but you are unauthorized to access this script. If you feel this is not correct, please feel free to contact our administrator at [email]admin@yoursite.com[/email]!<br><br>");
echo("For security purposes, your IP address has been stored. Your IP address is ".$ipaddress.".");
}
?>
How do I make this work??? The script doesn't recognize the CRON IP as blank...