Peanutz
-
Posts
2 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Downloads
Gallery
Store
Posts posted by Peanutz
-
-
Okay, so I already have a website made the old fasion way and I wanted to learn OOP so I intend to completely rework the code. Since I am a total noob at this I already came across a problem I don't know the answer. Yes I did go through the basic tutorial.
I wanted to start with my ban system and made these 2 classes to check for the user IP and make sure he aint using any crappy proxies and check if his IP is in my database.
class Ip { var $ip; function GetIp() { $ip = $_SERVER['REMOTE_ADDR']; if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } return $ip; } } class Ban extends Ip{ var $ip; function __construct() { $this->ip = Ip::GetIp(); } function CheckBan($ip){ $query = mysql_query("SELECT * FROM Banned"); if(mysql_num_rows($query) > 0){ while($row = mysql_fetch_array( $query )) { $deny[] = $row['IP']; } if (in_array ($ip, $deny)) { $Status = "banned"; return $Status; }else { // this is for wild card matches foreach($deny as $bannedip) { if(preg_match("/$bannedip/",$ip)) { $Status = "banned"; return $Status; } } } } } }
If the result is a string "banned" then we redirect him to the banned.php page
$Ban = new Ban(); if($Ban->CheckBan($Ban) == "banned") {$page = "banned";}
But I get this error
Warning: preg_match() expects parameter 2 to be string, object given in C:\wamp\www\class.phpI understand that it means that the $ip is not a string but an object but I dont know how to transform it into a string >.<
And I dont understand why is it defined as an object, I thought return $ip in the Ip class would return a string...
Starting with OOP, ran in a problem
in PHP
Posted
Oh my, thank you.. Been watching the code and tutorials for a bit too long I guess and did not spot that one lol