Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-04-2007, 03:17 PM   #16 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 651
DJMaze is on a distinguished road
$ip_from = "192.168.0.0";

vs

$ip_from = "19.216.80.0";

What do both result in after you did str_replace(".","",$ip_from) in both?

And no, don't ask about IPv6 routines!!!!
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 08-05-2007, 03:55 PM   #17 (permalink)
unknownsheep
Recruit
 
Join Date: Aug 2007
Posts: 3
unknownsheep is on a distinguished road
Quote:
Originally Posted by DJMaze View Post
$ip_from = "192.168.0.0";

vs

$ip_from = "19.216.80.0";

What do both result in after you did str_replace(".","",$ip_from) in both?

And no, don't ask about IPv6 routines!!!!
Ahh, didn't think so far.

How about?

PHP Code:
$ip $_SERVER['REMOTE_ADDR'];
$ip explode(".",$ip);

$ip_from "192.168.0.0";
$ip_to "192.168.255.255";

$ip_from explode(".",$ip_from);
$ip_to explode(".",$ip_to);

$a 0;
while(
$a <= 3) {
if (
$ip[$a] < $ip[$a] || $ip[$a] > $ip_to[$a]) { die("Denied"); }
$a++;

unknownsheep is offline   Reply With Quote
Old 08-05-2007, 11:56 PM   #18 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 651
DJMaze is on a distinguished road
PHP: ip2long - Manual
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 10-30-2007, 08:33 PM   #19 (permalink)
ibenk
Recruit
 
Join Date: Oct 2007
Posts: 5
ibenk is on a distinguished road
Quote:
Originally Posted by sde View Post
if you didn't want to use regular expressions, and the IPs in your IP array always started at the beginning of the IP, then you could do something like this:
PHP Code:
<?php
function checkIP($ip_to_match$ip_array) {

  
// make sure this is an array before we use foreach
  
if (is_array($ip_array)) {

    
// loop through ip array
    
foreach ($ip_array as $ip) {

      
// first test if there is a match, then test if the match starts at the beginning
      
if (strstr($ip_to_match$ip) && strpos($ip_to_match$ip)==0) {
        return 
true;
      }
    }
  }

  return 
false;
}

$ban_array = array(
  
'216.47.55.141',
  
'72.47.147',
  
'74.171',
  
'58'
);

if (
checkIP($_SERVER['REMOTE_ADDR'], $ban_array)) {
  echo 
"This page is not accessible.";
  exit;
}
?>
I'm sorry, this old thread i reply on this time, cause i really need help. So, the code above is work perfectly for me, but there's one option that i looking for. And cause i'm newbie, so can't figure it. I wanna the result is look like :

You ip address xxx.xxx.xxx. has been banned from this site !

So, in the echo syntax i put $ip, so it look like below:

You ip address $ip has been banned from this site !

but it doesn't work, i also change the $ip on message above with $ban_array, and $ip_to_match too...but still doesn't work.

so, what's the syntax i must add into the message? please tell me!
ibenk is offline   Reply With Quote
Old 10-31-2007, 06:34 AM   #20 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
redhead is on a distinguished road
$_server['remote_addr']
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 11-01-2007, 12:52 PM   #21 (permalink)
ibenk
Recruit
 
Join Date: Oct 2007
Posts: 5
ibenk is on a distinguished road
@redhead

thanks but i got error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/ibenk/public_html/ban.php on line 18
ibenk is offline   Reply With Quote
Old 11-02-2007, 07:24 AM   #22 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,694
redhead is on a distinguished road
It's case sensitive and should be: $_SERVER['REMOTE_ADDR']
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 11-09-2007, 11:56 AM   #23 (permalink)
ibenk
Recruit
 
Join Date: Oct 2007
Posts: 5
ibenk is on a distinguished road
sorry for the late reply,

i still got error, and now the error appear in line 28, exactly in :

echo "Your ip address $_SERVER['REMOTE_ADDR'] has been banned from this site !";
ibenk is offline   Reply With Quote
Old 05-21-2008, 03:07 AM   #24 (permalink)
cokacola
Recruit
 
Join Date: May 2008
Posts: 3
cokacola is on a distinguished road
Smile a little old but..

Quote:
Originally Posted by ibenk View Post
sorry for the late reply,

i still got error, and now the error appear in line 28, exactly in :

echo "Your ip address $_SERVER['REMOTE_ADDR'] has been banned from this site !";
I know this is a little old...well a year old but shouldn't it be
PHP Code:
echo "Your IP Address " $_SERVER['REMOTE_ADDR'] . " has been banned from this site !"
That should work, but do not forget to note the dots inbetween....
cokacola is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
php script that can upload binary data infinite_root PHP 9 08-27-2004 06:03 PM
PHP Comes of Age sde Code Newbie News 0 04-14-2004 11:41 AM
sending POST multiple post requests in one php script. sde PHP 2 08-09-2003 05:10 PM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM
Question about a php prediction script(Great Site!) Geetazz PHP 15 06-12-2002 05:37 PM


All times are GMT -8. The time now is 04:26 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting