473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Tweaking a script

I came across this free script on the net that compares the IP address of a
surfer to a list (1.list). If there is a match, the surfer gets the message
banned. If there is no match, the rest of the php script runs.

Is there an easy way to tweak the file so that
1. If there is a match of the surfers IP address to one in the list
(1.list), rather then get a banned message, the rest of the php script runs.
2. If the surfers IP address does not match any of the IP address in the
list (1.list), then instead of echo 'banned'; the surfer is redirected to
another webpage.

Thank you

<?php
$IP = $_SERVER['REMOTE_ADDR'];
$IP_array = file('../info/1.list');
$IP_array = str_replace("\n", "", $IP_array);
$IP_array = str_replace("\r", "", $IP_array);
foreach ($IP_array as $IP_test) {
if (substr_count($IP, $IP_test) != "0") {

echo 'banned';

die();
}
}
************* REST OF THE SCRIPT *************
Jun 6 '06 #1
10 2870
carmen wrote:
I came across this free script on the net that compares the IP address of a
surfer to a list (1.list). If there is a match, the surfer gets the message
banned. If there is no match, the rest of the php script runs.

Is there an easy way to tweak the file so that
1. If there is a match of the surfers IP address to one in the list
(1.list), rather then get a banned message, the rest of the php script runs.
2. If the surfers IP address does not match any of the IP address in the
list (1.list), then instead of echo 'banned'; the surfer is redirected to
another webpage.

Thank you

<?php
$IP = $_SERVER['REMOTE_ADDR'];
$IP_array = file('../info/1.list');
$IP_array = str_replace("\n", "", $IP_array);
$IP_array = str_replace("\r", "", $IP_array);
foreach ($IP_array as $IP_test) {
if (substr_count($IP, $IP_test) != "0") {

echo 'banned';

die();
}
}
************* REST OF THE SCRIPT *************

You can negate the the result of the "$IP_array as $IP_test" with the !

foreach (!($IP_array as $IP_test)) {

that should do the trick.
//Aho
Jun 6 '06 #2
J.O. Aho wrote:
You can negate the the result of the "$IP_array as $IP_test" with the
!
foreach (!($IP_array as $IP_test)) {


I don't think you can:

$a = array(1,2,3);

foreach (!($a as $num)) {
print $num;
}

Result:

Parse error: parse error, unexpected T_AS in [...] on line [...]
JW
Jun 6 '06 #3
carmen wrote:
Is there an easy way to tweak the file so that
1. If there is a match of the surfers IP address to one in the list
(1.list), rather then get a banned message, the rest of the php
script runs. 2. If the surfers IP address does not match any of the IP
address in
the list (1.list), then instead of echo 'banned'; the surfer is
redirected to another webpage.


$IP = $_SERVER['REMOTE_ADDR'];
$IP_array = file('../info/1.list');
$IP_array = str_replace(array("\n", "\r"), "", $IP_array);
if (!in_array($IP, $IP_array)) {
header("Location: banned.php");
exit;
}
JW
Jun 6 '06 #4

I think this is the easiest :
<?php
$IP = $_SERVER['REMOTE_ADDR'];
$IP_array = file('../info/1.list');

if (!array_search($IP, $IP_array))
die ("Banned");
else
echo "welcome";

?>

regards,

Lorento
--
http://www.mastervb.net
http://www.padbuilder.com
http://www.sederet.com

Jun 6 '06 #5
lorento wrote:
I think this is the easiest :
<?php
$IP = $_SERVER['REMOTE_ADDR'];
$IP_array = file('../info/1.list');

if (!array_search($IP, $IP_array))
die ("Banned");


This way, the script will also die when $IP occupies the first index in the
array; therefore, you should apply the identity operator:

if (false !== array_search($IP, $IP_array))
JW
Jun 6 '06 #6

"carmen" <dd**@kkdi.cka> wrote in message
news:KU9hg.246937$P01.8300@pd7tw3no...
I came across this free script on the net that compares the IP address of a
surfer to a list (1.list). If there is a match, the surfer gets the
message banned. If there is no match, the rest of the php script runs.

Is there an easy way to tweak the file so that
1. If there is a match of the surfers IP address to one in the list
(1.list), rather then get a banned message, the rest of the php script
runs.
2. If the surfers IP address does not match any of the IP address in the
list (1.list), then instead of echo 'banned'; the surfer is redirected to
another webpage.

Thank you

<?php
$IP = $_SERVER['REMOTE_ADDR'];
$IP_array = file('../info/1.list');
$IP_array = str_replace("\n", "", $IP_array);
$IP_array = str_replace("\r", "", $IP_array);
foreach ($IP_array as $IP_test) {
if (substr_count($IP, $IP_test) != "0") {

echo 'banned';

die();
}
}
************* REST OF THE SCRIPT *************


Would this work?

<?php
$IP = $_SERVER['REMOTE_ADDR'];
$IP_array = file('../info/1.list');
$IP_array = str_replace("\n", "", $IP_array);
$IP_array = str_replace("\r", "", $IP_array);
foreach ($IP_array as $IP_test) {
if (substr_count($IP, $IP_test) != "0") {

************* REST OF THE SCRIPT *************

die();
}
}
BANNED MESSAGE HERE
Jun 6 '06 #7
carmen wrote:
I came across this free script on the net that compares the IP address of a
surfer to a list (1.list). If there is a match, the surfer gets the message
banned. If there is no match, the rest of the php script runs.

Is there an easy way to tweak the file so that
1. If there is a match of the surfers IP address to one in the list
(1.list), rather then get a banned message, the rest of the php script runs.
2. If the surfers IP address does not match any of the IP address in the
list (1.list), then instead of echo 'banned'; the surfer is redirected to
another webpage.

Thank you

<?php
$IP = $_SERVER['REMOTE_ADDR'];
$IP_array = file('../info/1.list');
$IP_array = str_replace("\n", "", $IP_array);
$IP_array = str_replace("\r", "", $IP_array);
foreach ($IP_array as $IP_test) {
if (substr_count($IP, $IP_test) != "0") {

echo 'banned';

die();
}
}
************* REST OF THE SCRIPT *************


Are you using Apache? If so - just use their configuration directives - either
in httpd.conf or .htaccess.

Much easier to use the correct tool for the job.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 6 '06 #8
In message <KU9hg.246937$P01.8300@pd7tw3no>, carmen <dd**@kkdi.cka>
writes
I came across this free script on the net that compares the IP address of a
surfer to a list (1.list). If there is a match, the surfer gets the message
banned. If there is no match, the rest of the php script runs.


I see you've got some responses already, which I hope you find helpful.

I just wanted to add that banning particular IP addresses probably won't
achieve very much. Here in the UK most Internet users use a dynamically
allocated IP address, and it's probably the same elsewhere. So, for
example, disconnecting from Internet and then reconnecting would give me
a different IP address.

And there are also services, such as
<http://www.anonymizer.com/home.html> that will 'hide' visitors IP
address from the website they're visiting.
--
Martin Jay
Phone/SMS: +44 7740 191877
Fax: +44 870 915 2124
Jun 6 '06 #9
Martin

Just a heads up on this ... What actually works is to reverse your thinking
- you ban the anonymous users based on updated lists of anonymous proxies

I actually get it done at my firewall - we are a bit rude about it ... If
users come from any of the anonymous proxies around the world they just
don't see some of our managed servers - no redirection no nothing

Once an IP drops off the anonymous lists the users can get back in - there
are many publicly available anonymous proxy lists which you can use to block
with.

We find that we have greatly reduced the server attack attempts we are
getting - we also have a manually updated list of rogue IP which we clear on
a 3 monthly cycle

Cheers
moosus
in article KV**************@spam-free.org.uk, Martin Jay at
ma****@spam-free.org.uk wrote on 7/6/06 12:28 AM:
In message <KU9hg.246937$P01.8300@pd7tw3no>, carmen <dd**@kkdi.cka>
writes
I came across this free script on the net that compares the IP address of a
surfer to a list (1.list). If there is a match, the surfer gets the message
banned. If there is no match, the rest of the php script runs.


I see you've got some responses already, which I hope you find helpful.

I just wanted to add that banning particular IP addresses probably won't
achieve very much. Here in the UK most Internet users use a dynamically
allocated IP address, and it's probably the same elsewhere. So, for
example, disconnecting from Internet and then reconnecting would give me
a different IP address.

And there are also services, such as
<http://www.anonymizer.com/home.html> that will 'hide' visitors IP
address from the website they're visiting.


Jun 6 '06 #10
In message <C0AC4B5B.6866%junk{@}fishingmonthly.com.au>, moosus
<junk{@}fishingmonthly.com.au> writes
Just a heads up on this ... What actually works is to reverse your thinking
- you ban the anonymous users based on updated lists of anonymous proxies

I actually get it done at my firewall - we are a bit rude about it ... If
users come from any of the anonymous proxies around the world they just
don't see some of our managed servers - no redirection no nothing

Once an IP drops off the anonymous lists the users can get back in - there
are many publicly available anonymous proxy lists which you can use to block
with.

We find that we have greatly reduced the server attack attempts we are
getting - we also have a manually updated list of rogue IP which we clear on
a 3 monthly cycle


I was talking to a friend about a similar thing yesterday.

He wasn't able to get a response from <http://www.jinglemad.com/>, but I
could view it without any problems. We both use the same Internet
Provider. The only real difference between our setups is that I use a
dynamically allocated IP address and his is fixed. His trace route
ended with the following:

8 157 ms 153 ms 152 ms 209.51.149.109
9 111 ms 107 ms 105 ms l3-atl-8.gnax.net [209.51.131.18]
10 * * * Request timed out.

The same trace route for me ended with:

7 123 ms 124 ms 123 ms 209.51.149.109
8 110 ms 123 ms 110 ms l3-atl-8.gnax.net [209.51.131.18]
9 124 ms 123 ms 124 ms ice.dnsprotect.com [207.210.68.18]

My 'guess' is that his IP address has found its way onto a block list.

I suggested he tried <http://www.anonymizer.com/> to access the site and
it worked. :)

Apparently he's not been able to visit Jinglemad.com for three weeks
now, and thought it was down. :)
--
Martin Jay
Phone/SMS: +44 7740 191877
Fax: +44 870 915 2124
Jun 7 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Sandy Norton | last post by:
If we are going to be stuck with @decorators for 2.4, then how about using blocks and indentation to elminate repetition and increase readability: Example 1 --------- class Klass: def...
6
by: Mike Daniel | last post by:
I am attempting to use document.write(pageVar) that displays a new html page within a pop-up window and the popup is failing. Also note that pageVar is a complete HTML page containing other java...
7
by: Frank-René Schäfer | last post by:
Case: -- class X has occupies tiny amount of memory: sizeof(X) is only a little greater than sizeof(void*). -- X instantiates thousands of objects and memory does matter. -- The class has...
3
by: Water Cooler v2 | last post by:
Questions: 1. Can there be more than a single script block in a given HEAD tag? 2. Can there be more than a single script block in a given BODY tag? To test, I tried the following code. None...
2
by: bilaribilari | last post by:
Hi all, I am using Tidy (C) for parsing html pages. I encountered a page that has some script as follows: <script> .... var abc = "<script>some stuff here</" + "script>"; .... </script>
0
by: Anastasios Hatzis | last post by:
I would like to let my setup script know if the user has provided a custom path for the data_files of my distribution, e.g. by using the --install-data option, so the setup can automagically change...
5
by: RageARC | last post by:
I would like to know any configurations to speed up PHP's execution. I have increased the memory limit and decreased the amount of extensions loaded, but do you know anything else?
1
by: =?Utf-8?B?UGxhdGVyaW90?= | last post by:
I have several pages that have 3 tabs. One of the desired effects is to preserve whatever tab the user may have selected from page-to-page. So I use the following Client-Side script to remember a...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.