473,403 Members | 2,359 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,403 software developers and data experts.

BAN IP (second try)

Say I want to ban all IPs in the range 123.123 X X from access to some areas
on my server. BUT at the same time allow just ONE of the IPs which relies in
this IP-range, for example: 123.123.123.12

Is that possible through PHP? I don't want to mess up with .htaccess files
and so on.

Code?
May 22 '06 #1
2 1638
John wrote:
Say I want to ban all IPs in the range 123.123 X X from access to some
areas on my server. BUT at the same time allow just ONE of the IPs which
relies in this IP-range, for example: 123.123.123.12

Is that possible through PHP? I don't want to mess up with .htaccess files
and so on.

Code?


Hi,

Why not approach this with plain strings?

$ip = SERVER['REMOTE_ADDR'];
$allowIP = array('123.123.123.12' , '123.123.123.115');

$passOK = 'Y';
if (substr($ip,0,7) == '123.123'){
// not welcome, unless in $allowIP
if (in_array($ip,$allowIP)){
$passOK = 'Y';
} else {
$passOK = 'N';
}
}

If you need more complex fitting of IP-addresses than just simple
'startstring-fitting', you'll need more complex code of course.

Regards,
Erwin Moller
May 22 '06 #2
Thanks, excellent, just what I was looking for!!!

Honour to you!!
"Erwin Moller"
<si******************************************@spam yourself.com> wrote in
message news:44***********************@news.xs4all.nl...
John wrote:
Say I want to ban all IPs in the range 123.123 X X from access to some
areas on my server. BUT at the same time allow just ONE of the IPs which
relies in this IP-range, for example: 123.123.123.12

Is that possible through PHP? I don't want to mess up with .htaccess
files
and so on.

Code?


Hi,

Why not approach this with plain strings?

$ip = SERVER['REMOTE_ADDR'];
$allowIP = array('123.123.123.12' , '123.123.123.115');

$passOK = 'Y';
if (substr($ip,0,7) == '123.123'){
// not welcome, unless in $allowIP
if (in_array($ip,$allowIP)){
$passOK = 'Y';
} else {
$passOK = 'N';
}
}

If you need more complex fitting of IP-addresses than just simple
'startstring-fitting', you'll need more complex code of course.

Regards,
Erwin Moller

May 22 '06 #3

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

Similar topics

5
by: TG | last post by:
Conditions: Register globals is set to on. Parse html as php is set to on. I have two forms OrderTest1 and OrderTest2 and need to be able to validate the data from OrderTest1 before passing to...
0
by: Alex Martelli | last post by:
Greetings, fellow Pythonistas! We (Alex Martelli, David Ascher and Anna Martelli Ravenscroft) are in the process of selecting recipes for the Second Edition of the Python Cookbook. Please...
3
by: Huahe | last post by:
I try to delete a file in a for each loop. My code checks if the file exists and if it does, it will delete the file and create a new file with the same name. The first time it works perfect, but...
21
by: Jaspreet | last post by:
I was working on some database application and had this small task of getting the second highes marks in a class. I was able to do that using subqueries. Just thinking what is a good way of...
1
by: Steven | last post by:
Hi all, I have been having an odd problem that I've been trying to track down for a few days, and I'm coming up short. I have a user control that encapsulates search functionality for a set of...
4
by: bienwell | last post by:
Hi all, I'd like to use TRY, CATCH to open my database connection. I have 2 servers that have the same table name "myTable". If the first connection to Server1 is failed, then the program will...
0
by: Wayne | last post by:
Original Post: The following problem started on my PC about a week ago and I can't link it to any specific change. I'm using Access XP. If I have any database open and try to open any other...
4
by: tneufeld | last post by:
I am using a ListView control to display 2 columns of data that I populate manually. I can get the data in the first column easily enough. its when i try to get the data in the second column...
7
by: Peter Laan | last post by:
Is there a simple way to encapsulate the functionality to redo a method call a second time in case a specific exception is thrown? We are sending commands to an external system and if the sessionId...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.