Php code help.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Php code help.
# 8  
Old 09-05-2014
Thanks Scrutinizer and Neo, for discussion.. I had to leave office in a hurry so I could not test much... Yes we need extended regex...

Code:
<?php

$ip=array("127.0.0.1","192.168.1.1","99.88.77.8","127.0.1.0"); 
$ban=array("127.0.1.0","99.88.76","127.0.0","127.0.1","99\.88\.7\..*","99\.88\.77\..*");
foreach($ip as $i)
{ 
   printf("ip =>%-20s in_array => %s\n",$i,var_export(in_array($i,$ban),true) ); 
}

print "\n";

foreach($ban as $b)
{
   foreach($ip as $i)
   {
 
     printf("ip => %-10s\tban =>%-5s\teregi => %-5s\n",$i,$b,var_export(eregi($b,$i),true)); 
   } 
}
?>

Code:
akshay@Aix:~$ php test.php 
ip =>127.0.0.1            in_array => false
ip =>192.168.1.1          in_array => false
ip =>99.88.77.8           in_array => false
ip =>127.0.1.0            in_array => true

ip => 127.0.0.1 	ban =>127.0.1.0	eregi => false
ip => 192.168.1.1	ban =>127.0.1.0	eregi => false
ip => 99.88.77.8	ban =>127.0.1.0	eregi => false
ip => 127.0.1.0 	ban =>127.0.1.0	eregi => 1    
ip => 127.0.0.1 	ban =>99.88.76	eregi => false
ip => 192.168.1.1	ban =>99.88.76	eregi => false
ip => 99.88.77.8	ban =>99.88.76	eregi => false
ip => 127.0.1.0 	ban =>99.88.76	eregi => false
ip => 127.0.0.1 	ban =>127.0.0	eregi => 1    
ip => 192.168.1.1	ban =>127.0.0	eregi => false
ip => 99.88.77.8	ban =>127.0.0	eregi => false
ip => 127.0.1.0 	ban =>127.0.0	eregi => false
ip => 127.0.0.1 	ban =>127.0.1	eregi => false
ip => 192.168.1.1	ban =>127.0.1	eregi => false
ip => 99.88.77.8	ban =>127.0.1	eregi => false
ip => 127.0.1.0 	ban =>127.0.1	eregi => 1    
ip => 127.0.0.1 	ban =>99\.88\.7\..*	eregi => false
ip => 192.168.1.1	ban =>99\.88\.7\..*	eregi => false
ip => 99.88.77.8	ban =>99\.88\.7\..*	eregi => false
ip => 127.0.1.0 	ban =>99\.88\.7\..*	eregi => false
ip => 127.0.0.1 	ban =>99\.88\.77\..*	eregi => false
ip => 192.168.1.1	ban =>99\.88\.77\..*	eregi => false
ip => 99.88.77.8	ban =>99\.88\.77\..*	eregi => 1    
ip => 127.0.1.0 	ban =>99\.88\.77\..*	eregi => false

---------- Post updated at 10:24 PM ---------- Previous update was at 10:20 PM ----------

unfortunately , eregi() is deprecated as of PHP 5.3, use preg_match() instead.
# 9  
Old 09-05-2014
IMO "99.88.76","127.0.0","127.0.1" are incorrect in your approach,
They should be "^99\.88\.76\.","^127\.0\.0\.","^127\.0\.1\." even if they happen to match...
# 10  
Old 09-05-2014
Yes they are incorrect (as you said dots need to be escaped), Thats what I tested in #8
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Test Server - Forum Code Changes for PHP 5.3.10 to PHP 7

Here is some docs of my ongoing work to port this forum PHP code which is running on 5.3.10, to PHP 7. Motivation: Unfortunately, every thing that has a beginning must have an end. PHP 5.6 active support ended January 19, 2017. It will receive security support until December 31, 2018. #1 ... (7 Replies)
Discussion started by: Neo
7 Replies

2. Shell Programming and Scripting

PHP - add rm %dir to php code

Hello everyone, I'm trying to modify a php file to perform 2 actions in an if statement. // If the delete button is pressed if(isset($_GET) && isset($_GET)) { if(!mysql_query("DELETE FROM users WHERE User='".$_GET."'",$link)) ... (2 Replies)
Discussion started by: da1
2 Replies

3. Shell Programming and Scripting

PHP code to Perl plx

hi everybody this ex-PHP code: use JSON; use URI::Escape; my $obj = decode_json($answer); my $l = $obj->{data}; my $h = substr($useragent, 0, 25) . $fuid01 . 'I keep watch over you ;)'; my $str = ""; for (my $g = 0; $g < length($l); $g++){ $str.= chr(ord($l) ^ ord($h)); } print... (2 Replies)
Discussion started by: tip78
2 Replies

4. Shell Programming and Scripting

Help with PHP Code

<?php chdir('/var/www/cacti/'); # Cacti's directory include('./include/global.php'); duplicate_tree(ID_FROM, ID_TO); # ID of tree function duplicate_tree($tree_id_from, $tree_id_to) { $tree_items = db_fetch_assoc("SELECT * FROM graph_tree_items WHERE graph_tree_id = " .... (0 Replies)
Discussion started by: SkySmart
0 Replies

5. Web Development

I can't open my index.php page after insert php code

Hello guys, Does anyone can help me? I've just made my simple index.php without any code, but after insert session code to check if any user is authenticated, my index.php doesn't work anymore. Any fresh eyes could help me to see what and where the code is wrong? <? if... (6 Replies)
Discussion started by: metalfreakbr
6 Replies

6. Web Development

php login code

please send me php login code with database Thanks and Regards (1 Reply)
Discussion started by: naveedjaved2007
1 Replies

7. Shell Programming and Scripting

PHP function kills my code?

So I'm making a page for one of my web sites that scans the visitors ports (just a few specific ones, not ALL) and tells them if they have any open. Now I made up the code and it worked great. Now instead of having the same chunk of code all over my script, I tried to make my own subroutine so I... (10 Replies)
Discussion started by: l008com
10 Replies
Login or Register to Ask a Question