Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
[PHP - PDO] VPN/Proxy Restriction
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="MayoMayn" data-source="post: 397003" data-attributes="member: 71840"><p>Since y'all got me in a good mood, I'm going to release this script that I coded.</p><p>For more information about how this service works check out the website that checks the IP's:</p><p><u><a href="http://getipintel.net" target="_blank">http://getipintel.net</a></u></p><p><u></u></p><p>Okay, so first off we gotta create a function called <strong>getIP() </strong></p><p>[PHP]</p><p>public function getIP() </p><p> {</p><p> //Just get the headers if we can or else use the SERVER global</p><p> if(function_exists('apache_request_headers')) {</p><p> $headers = apache_request_headers();</p><p> } else {</p><p> $headers = $_SERVER;</p><p> }</p><p> //Get the forwarded IP if it exists</p><p> if(array_key_exists('X-Forwarded-For', $headers) && filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {</p><p> $ip = $headers['X-Forwarded-For'];</p><p> } elseif(array_key_exists('HTTP_X_FORWARDED_FOR', $headers) && filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {</p><p> $ip = $headers['HTTP_X_FORWARDED_FOR'];</p><p> } else {</p><p> $ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);</p><p> }</p><p></p><p> return $ip;</p><p> }</p><p>[/PHP]</p><p></p><p>Okay, so in the same class, create a function called <strong>curl()</strong></p><p>[PHP]</p><p>public function curl($url, $json=false)</p><p>{</p><p> //Check if server has curl library installed</p><p> if(function_exists('curl_init')) {</p><p> // Initiate curl</p><p> $ch = curl_init();</p><p> // Disable SSL verification</p><p> curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);</p><p> // Will return the response, if false it prints the response</p><p> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);</p><p> // Set the url</p><p> curl_setopt($ch, CURLOPT_URL, $url);</p><p> // Execute</p><p> $response = curl_exec($ch);</p><p> // Close curl</p><p> curl_close($ch);</p><p> } else {</p><p> // Ordinary get content</p><p> $response = file_get_contents($url);</p><p> }</p><p></p><p> if($json == true) {</p><p> //Return as JSON data.</p><p> $response = json_decode($response, true);</p><p> }</p><p></p><p> return $response;</p><p> }</p><p>[/PHP]</p><p></p><p>So for the second last step, we gotta create a function called <strong>validIP()</strong> which validates the visitors IP</p><p>[PHP]</p><p>public function validIP()</p><p>{</p><p> $db = $this->db;</p><p> $config = $this->config;</p><p> $uip = $this->getIP();</p><p> //Check if session variables are set</p><p> if(isset($_SESSION['ip_banned']) && isset($_SESSION['visitor_ip']) && $_SESSION['visitor_ip'] === $uip) {</p><p> if($_SESSION['ip_banned'] == 0) {</p><p> $ipBanned = 0;</p><p> $status = true;</p><p> } else {</p><p> $ipBanned = 1;</p><p> $status = false;</p><p> }</p><p> } else {</p><p> //Check if Visitor exists inside our Database Table</p><p> $stmt = $db->query("SELECT `banned`,`result` FROM `visitor_ips` WHERE `ip` = :ip LIMIT 1");</p><p> $stmt->bindParam(':ip', $uip, $db->PARAM_STR);</p><p> $stmt->execute();</p><p> if($stmt->rowCount() > 0) {</p><p> $ip = $db->assoc($stmt);</p><p> if($ip['banned'] == '0' && $ip['result'] < '1') {</p><p> $ipBanned = 0;</p><p> $status = true;</p><p> } else {</p><p> $ipBanned = 1;</p><p> $status = false;</p><p> }</p><p> } else {</p><p> //Get url for IP Validation</p><p> $url = 'https://check.getipintel.net/check.php?ip='.$uip.'&flags=f&format=json&oflags=bc&contact='.$config->hotel('mail');</p><p> //Initiate</p><p> $json = $this->curl($url, true);</p><p></p><p> if($json['status'] == "success") {</p><p> if($json['BadIP'] == "0") {</p><p> $continue = true;</p><p> if($config->hotel('c_allow_check') == true) {</p><p> if(!in_array($json['Country'], $config->hotel('c_allow'))) {</p><p> $continue = false;</p><p> $ipBanned = 1;</p><p> }</p><p> }</p><p> if($continue == true) {</p><p> if($json['result'] >= '1') {</p><p> $ipBanned = 1;</p><p> } else {</p><p> $ipBanned = 0;</p><p> }</p><p> }</p><p> } else {</p><p> $ipBanned = 1;</p><p> }</p><p> } else {</p><p> $ipBanned = 0;</p><p> }</p><p> // If Visitor does not exists in our table insert them into.</p><p> $stmt = $db->query("INSERT INTO `visitor_ips` (`ip`,`banned`,`result`,`agent`) VALUES (:ip,:b,:r,:a)");</p><p> $data = [</p><p> ':ip' => $uip,</p><p> ':b' => $ipBanned,</p><p> ':r' => $json['result'],</p><p> ':a' => $_SERVER['HTTP_USER_AGENT']</p><p> ];</p><p> if($stmt->execute($data)) {</p><p> if($ipBanned == 0) {</p><p> $status = true;</p><p> } else {</p><p> $status = false;</p><p> }</p><p> }</p><p> }</p><p> $_SESSION['visitor_ip'] = $uip;</p><p> $_SESSION['ip_banned'] = $ipBanned;</p><p> }</p><p></p><p> return $status;</p><p> }</p><p>[/PHP]</p><p></p><p>Run this SQL as a query to create the table needed.</p><p>[CODE]</p><p>DROP TABLE IF EXISTS `visitor_ips`;</p><p>CREATE TABLE `visitor_ips` (</p><p> `id` int(11) NOT NULL AUTO_INCREMENT,</p><p> `ip` varchar(45) NOT NULL,</p><p> `banned` enum('0','1') NOT NULL,</p><p> `result` varchar(255) NOT NULL,</p><p> `agent` text NOT NULL,</p><p> PRIMARY KEY (`id`)</p><p>) ENGINE=InnoDB DEFAULT CHARSET=utf8;</p><p>[/CODE]</p><p>For this to work, you gotta recode the MySQL queries so it works for your own service.</p><p>By researching, you can create the most amazing stuff.</p></blockquote><p></p>
[QUOTE="MayoMayn, post: 397003, member: 71840"] Since y'all got me in a good mood, I'm going to release this script that I coded. For more information about how this service works check out the website that checks the IP's: [U][URL]http://getipintel.net[/URL] [/U] Okay, so first off we gotta create a function called [B]getIP() [/B] [PHP] public function getIP() { //Just get the headers if we can or else use the SERVER global if(function_exists('apache_request_headers')) { $headers = apache_request_headers(); } else { $headers = $_SERVER; } //Get the forwarded IP if it exists if(array_key_exists('X-Forwarded-For', $headers) && filter_var($headers['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { $ip = $headers['X-Forwarded-For']; } elseif(array_key_exists('HTTP_X_FORWARDED_FOR', $headers) && filter_var($headers['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { $ip = $headers['HTTP_X_FORWARDED_FOR']; } else { $ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); } return $ip; } [/PHP] Okay, so in the same class, create a function called [B]curl()[/B] [PHP] public function curl($url, $json=false) { //Check if server has curl library installed if(function_exists('curl_init')) { // Initiate curl $ch = curl_init(); // Disable SSL verification curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Will return the response, if false it prints the response curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Set the url curl_setopt($ch, CURLOPT_URL, $url); // Execute $response = curl_exec($ch); // Close curl curl_close($ch); } else { // Ordinary get content $response = file_get_contents($url); } if($json == true) { //Return as JSON data. $response = json_decode($response, true); } return $response; } [/PHP] So for the second last step, we gotta create a function called [B]validIP()[/B] which validates the visitors IP [PHP] public function validIP() { $db = $this->db; $config = $this->config; $uip = $this->getIP(); //Check if session variables are set if(isset($_SESSION['ip_banned']) && isset($_SESSION['visitor_ip']) && $_SESSION['visitor_ip'] === $uip) { if($_SESSION['ip_banned'] == 0) { $ipBanned = 0; $status = true; } else { $ipBanned = 1; $status = false; } } else { //Check if Visitor exists inside our Database Table $stmt = $db->query("SELECT `banned`,`result` FROM `visitor_ips` WHERE `ip` = :ip LIMIT 1"); $stmt->bindParam(':ip', $uip, $db->PARAM_STR); $stmt->execute(); if($stmt->rowCount() > 0) { $ip = $db->assoc($stmt); if($ip['banned'] == '0' && $ip['result'] < '1') { $ipBanned = 0; $status = true; } else { $ipBanned = 1; $status = false; } } else { //Get url for IP Validation $url = 'https://check.getipintel.net/check.php?ip='.$uip.'&flags=f&format=json&oflags=bc&contact='.$config->hotel('mail'); //Initiate $json = $this->curl($url, true); if($json['status'] == "success") { if($json['BadIP'] == "0") { $continue = true; if($config->hotel('c_allow_check') == true) { if(!in_array($json['Country'], $config->hotel('c_allow'))) { $continue = false; $ipBanned = 1; } } if($continue == true) { if($json['result'] >= '1') { $ipBanned = 1; } else { $ipBanned = 0; } } } else { $ipBanned = 1; } } else { $ipBanned = 0; } // If Visitor does not exists in our table insert them into. $stmt = $db->query("INSERT INTO `visitor_ips` (`ip`,`banned`,`result`,`agent`) VALUES (:ip,:b,:r,:a)"); $data = [ ':ip' => $uip, ':b' => $ipBanned, ':r' => $json['result'], ':a' => $_SERVER['HTTP_USER_AGENT'] ]; if($stmt->execute($data)) { if($ipBanned == 0) { $status = true; } else { $status = false; } } } $_SESSION['visitor_ip'] = $uip; $_SESSION['ip_banned'] = $ipBanned; } return $status; } [/PHP] Run this SQL as a query to create the table needed. [CODE] DROP TABLE IF EXISTS `visitor_ips`; CREATE TABLE `visitor_ips` ( `id` int(11) NOT NULL AUTO_INCREMENT, `ip` varchar(45) NOT NULL, `banned` enum('0','1') NOT NULL, `result` varchar(255) NOT NULL, `agent` text NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; [/CODE] For this to work, you gotta recode the MySQL queries so it works for your own service. By researching, you can create the most amazing stuff. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
[PHP - PDO] VPN/Proxy Restriction
Top