Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-17-2008, 11:23 AM REMOTE_ADDR Range.
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
PHP Code:
$ip getenv("REMOTE_ADDR"); 
I'm looking to exclude a range of IP addresses from being added to my database in one of my scripts (mainly because they are search engine spiders).

Now I can exclude IP address easily with if else statements. And I have excluded my IP address, and google's spider. In this example 111.111.111.111 is my IP and 222.222.222.222 is google's spider.

PHP Code:
if ($ip != '111.111.111.111' || $ip != '222.222.222.222') {

// stuff to add to MySQL database


I want to exclude more IP addresses from other spiders, and I would normally just add

PHP Code:
|| $ip != 'oth.ip.add.ress' 
but what if I wanted to exclude a range of IP addresses, like Live Search which have about 10 IPs starting with 65.55.208

Isn't there some kind of way to exclude any number that follows 65.55.208.

Surely this is easy, its just not clear in any PHP tutorials.
Gilligan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-17-2008, 02:09 PM Re: REMOTE_ADDR Range.
Super Spam Talker

Latest Blog Post:
PSD Squirrel Launched
Posts: 933
Trades: 7
Hi Gilligan,

Yup... loads of ways - heres just one (and im not saying its the best way, but its a way)

PHP Code:
if(!ereg("^65.55.208"$ip)){ 
//not a spider so register code here ...

all the best

//edit: thought it would help if I told you what that does, for learning purposes... it just scans the variable $ip to see if it beginds 65.55.208.. if it does, nothing happens ( you could use an else to make something happen if you like) if it doesnt, runs the code inside the curelys
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by Sir P; 03-17-2008 at 02:14 PM..
Sir P is offline
Reply With Quote
View Public Profile Visit Sir P's homepage!
 
Old 03-17-2008, 03:21 PM Re: REMOTE_ADDR Range.
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Thanks for the reply, just want to ask one more question.

to fit:

PHP Code:
if(!ereg("^65.55.208"$ip)){  
//not a spider so register code here ... 

into my previous statement

PHP Code:
if ($ip != '111.111.111.111' || $ip != '222.222.222.222') {

// stuff to add to MySQL database


Would it simply become:

PHP Code:
if ($ip != '111.111.111.111' || $ip != '222.222.222.222' || !ereg("^65.55.208"$ip)) {

// stuff to add to MySQL database


And also, wouldn't it be

65.55.208.^

seeming as the list of similar IPs all have the same start?
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 03-17-2008, 03:46 PM Re: REMOTE_ADDR Range.
Super Spam Talker

Latest Blog Post:
PSD Squirrel Launched
Posts: 933
Trades: 7
yep you have included it into your current code correctly, good job/

Not sure what you mean on your final question.. you must put the ^ sign at the front as it checks for the string that follows the ^ at the start of the $ip variable...

basically, ^65.55.208 means is 65.55.208 at the start of the IP. You can remove the ^ sign all together and it will just check if 65.55.208 exists anywhere in the string
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Sir P is offline
Reply With Quote
View Public Profile Visit Sir P's homepage!
 
Old 03-17-2008, 05:27 PM Re: REMOTE_ADDR Range.
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Oh right, I thought ^65.55.208 meant that it checks everything before the IP, never mind then
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 03-17-2008, 05:38 PM Re: REMOTE_ADDR Range.
Super Spam Talker

Latest Blog Post:
PSD Squirrel Launched
Posts: 933
Trades: 7
nope, its the other way round
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Sir P is offline
Reply With Quote
View Public Profile Visit Sir P's homepage!
 
Old 03-18-2008, 03:22 AM Re: REMOTE_ADDR Range.
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
PHP Code:
if (!preg_match('!111.111.111.111|222.222.222.222|^65.55.208!'$_SERVER['REMOTE_ADDR'])) {
   
add_me();

__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Old 03-18-2008, 07:16 PM Re: REMOTE_ADDR Range.
Gilligan's Avatar
Website Designer

Posts: 1,670
Name: Stefan
Location: London, UK
Trades: 0
Just realised, using || is stupid to use in this case.

Basically, I wanted it to add stats if it isn't my ip or a search engine ip.

But || makes it so that if it is my ip, but isn't a search engine's ip (will always be true no matter what) then it will add my ip's stats anyway. Stupid eh?

Anyway I changed it to &&, makes more sense that way.
Gilligan is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to REMOTE_ADDR Range.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.20661 seconds with 12 queries