PDA

View Full Version : [TUT] PHP - Alert User By IP (FLATFILES)



lolwut
29-09-2007, 09:41 AM
I've commented the code. So read the orange bits if you don't get it.

Step 1) Create a ip.txt file, leave it blank for now. It's the file that remember's the IP you are alerting.
Step 2) Create a alert.txt file, leave it blank for now. It's the file that will remember the alert.
Step 3) Create a alert.php file, use the following code.


<?php
$ip = file_get_contents("ip.txt"); // This code gets the ip.txt file and variable-ises it.
$alert = file_get_contents("alert.txt"); // This code gets the alert.txt file and variable-ises it.

if($_SERVER['REMOTE_ADDR'] == $ip){ // If the users IP IS the one specified in ip.txt, do this:
echo("
<script language=\"JavaScript\">
<!--
alert('$alert');
//-->
</script>
");// The above lines print a JavaScript alert using the text in alert.txt to the user speicified in ip.txt
}else{ // If the users IP IS NOT the one speicified in ip.txt, do this:
echo("<br />");
} // End the script.
?>
Step 4) Edit the ip.txt and alert.txt files, ip.txt to whatever you want the IP of the user you're going to alert to be. And set alert.txt to whatever you want the message the user will send.

Please note: Some hosts, mostly non-cPanel ones, do NOT support the use of the file_get_contents(); PHP function. This is for reasons I don't quite understand, but that's the way it is.

Eccentric
29-09-2007, 09:44 AM
Its ok nicely commented but its not too secure, anyone could use it couldnt they :S:P just have to make sure permissions are set properly ;)!
what you could do is make a form that saves to a flatfile with the ip and what to alert them and just have a basic login for security ;)! well done on the whole.

lolwut
29-09-2007, 10:04 AM
Its ok nicely commented but its not too secure, anyone could use it couldnt they :S:P just have to make sure permissions are set properly ;)!
what you could do is make a form that saves to a flatfile with the ip and what to alert them and just have a basic login for security ;)! well done on the whole.

I considered, but I've already done this differently to use as part of my site panel. Thanks anyway, +Rep

Want to hide these adverts? Register an account for free!