Michael Zaporozhets
Michael Zaporozhets

Reputation: 24526

Sending PHP script to a specific IP address on site

I'm writing a basic text chat web app, and i'm trying to figure out the best and most secure way to implement a 'kicking' ability, preferably by somehow sending a PHP script to a specific IP address but any other method 'non-js' would be cool too.

At the moment I've written the ability to 'ban' by adding a defined IP to an array, and if the user refreshes it will header redirect them by cross-checking the array with a banlist and redirecting if found in the array.

Is there any way to possibly run this check in the background?

Upvotes: 1

Views: 1701

Answers (1)

user849137
user849137

Reputation:

BIG EDIT:

Okay, so here is a simple way of doing it (using boring text files):

Create another text file called bad_people.txt

Create a script to insert the naughty users IP address into the text file. Something like this:

$myFile = "../bad_people.txt";

$fh = fopen($myFile, 'a') or die("can't open file");

$ip_splitter="-::-"; //This is a splitter...Will be used to split each IP address in the text file to make it readable in future.

$bad_address = "22.22.22.22".$ip_splitter;

fwrite($fh, $bad_address);

fClose($fh);

So, you run the code above when you want to kick someone off the chat...

NOTE: See how I've used a splitter ($ip_splitter), to split each IP address in the text file. This will make it easier to read the file and insert all the addresses into an array.

Then, in the AJAX call (which I'm assuming runs in a infinite loop):

$myFile = "../bad_people.txt";

    $fh = fopen($myFile, 'r') or die("can't open file");

    $ip_splitter="-::-"; 

$bad_people_array=explode($ip_splitter,$fh);

$user_ip=$_SERVER['REMOTE_ADDR'];

foreach ($bad_people_array as $BAD_IP){

if($BAD_IP==$user_ip){

//do whatever here......

}//end of if the user is bad


}//end of for loop

So you run that script on your ajax call, along with your script to check for new messages....

and there you have it.

Upvotes: 1

Related Questions