{"id":6302,"date":"2023-10-18T14:47:43","date_gmt":"2023-10-18T14:47:43","guid":{"rendered":"https:\/\/royadata.io\/blog\/?p=6302"},"modified":"2023-10-18T14:47:43","modified_gmt":"2023-10-18T14:47:43","slug":"php-detect-proxy-anonymity-level","status":"publish","type":"post","link":"http:\/\/royadata.io\/blog\/php-detect-proxy-anonymity-level\/","title":{"rendered":"How to Detect Proxy Anonymity Level Using PHP"},"content":{"rendered":"<p><picture class=\"aligncenter size-full wp-image-481 perfmatters-lazy\" loading=\"lazy\"><source type=\"image\/webp\" data-srcset=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers.jpg.webp 800w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers-300x127.jpg.webp 300w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers-768x325.jpg.webp 768w\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns='http:\/\/www.w3.org\/2000\/svg'%20viewBox='0%200%20800%20339'%3E%3C\/svg%3E\" data-sizes=\"(max-width: 800px) 100vw, 800px\" \/><img decoding=\"async\" src=\"data:image\/svg+xml,%3Csvg%20xmlns='http:\/\/www.w3.org\/2000\/svg'%20viewBox='0%200%20800%20339'%3E%3C\/svg%3E\" alt=\"Anonymous can be a huge concern for developers\" width=\"800\" height=\"339\" data-src=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers.jpg\" data-srcset=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers.jpg 800w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers-300x127.jpg 300w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers-768x325.jpg 768w\" data-sizes=\"(max-width: 800px) 100vw, 800px\" loading=\"lazy\" \/>\n<\/picture>\n<noscript><picture class=\"aligncenter size-full wp-image-481\"><source type=\"image\/webp\" srcset=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers.jpg.webp 800w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers-300x127.jpg.webp 300w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers-768x325.jpg.webp 768w\" sizes=\"(max-width: 800px) 100vw, 800px\"\/><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers.jpg\" alt=\"Anonymous can be a huge concern for developers\" width=\"800\" height=\"339\" srcset=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers.jpg 800w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers-300x127.jpg 300w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Anonymous-can-be-a-huge-concern-for-developers-768x325.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\"\/>\n<\/picture>\n<\/noscript><\/p>\n<p>When building apps that involve <a href=\"https:\/\/www.bestproxyreviews.com\/?s=scraping\">scraping<\/a>, downloading data and <a href=\"https:\/\/www.bestproxyreviews.com\/?s=automation\">automation<\/a>, staying completely anonymous can be a huge concern for developers. Although there are many di\ufb00erent proxy checkers out there, most of them all seem to deliver slightly di\ufb00erent and unreliable results.<\/p>\n<p>This guide will walk you through the three steps and provide<strong> a clean PHP code to detect exactly how anonymous a specific proxy is<\/strong>.<\/p>\n<hr\/>\n<h2 id=\"what-are-the-different-levels-of-proxy-anonymity\" class=\"ftwp-heading\"><span class=\"ez-toc-section\" id=\"What_are_the_Different_Levels_of_Proxy_Anonymity\"><\/span>What are the Different Levels of Proxy Anonymity?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3 id=\"elite-high-anonymous\" class=\"ftwp-heading\"><span class=\"ez-toc-section\" id=\"Elite_High-Anonymous\"><\/span><a href=\"https:\/\/royadata.io\/blog\/what-is-an-elite-proxy\/\">Elite<\/a> (<a href=\"https:\/\/royadata.io\/blog\/high-anonymous-proxy\/\">High-Anonymous<\/a>)<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Your proxy is completely undetectable and your real IP will remain hidden. The server you connect to will have no idea you\u2019re using a proxy. These are the best proxies you will find and the level of anonymity and quality is unprecedented.<\/p>\n<h3 id=\"anonymous\" class=\"ftwp-heading\"><span class=\"ez-toc-section\" id=\"Anonymous\"><\/span><a href=\"https:\/\/royadata.io\/blog\/anonymous-proxy\/\">Anonymous<\/a><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Although your proxy IP is still hidden while connected to an anonymous proxy, some servers and proxy detection scripts will be able to detect that you\u2019re using a proxy. Although these proxies are still useful for whitehat practices and data mining, your original IP still has a slight chance of exposure.<\/p>\n<h3 id=\"transparent\" class=\"ftwp-heading\"><span class=\"ez-toc-section\" id=\"Transparent\"><\/span><a href=\"https:\/\/royadata.io\/blog\/transparent-proxy\/\">Transparent<\/a><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Your original IP will be exposed and everyone will know you\u2019re using a proxy. It is extremely risky and highly recommended to avoid using transparent proxies while trying to remain anonymous.<\/p>\n<p>Read more,<\/p>\n<ul>\n<li><a href=\"https:\/\/www.stupidproxy.com\/http-proxies-anonymity-level\/\">Different type of Anonymity level of HTTP proxies<\/a><\/li>\n<li><a href=\"https:\/\/royadata.io\/blog\/different-types-of-proxies\/#different-types-of-proxies-based-on-anonymity-level\">Transparent Proxy Vs. Anonymous Proxy Vs. Elite Proxy<\/a><\/li>\n<\/ul>\n<p><picture class=\"aligncenter size-full wp-image-483 perfmatters-lazy\" loading=\"lazy\"><source type=\"image\/webp\" data-srcset=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent.jpg.webp 800w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent-300x129.jpg.webp 300w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent-768x330.jpg.webp 768w\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns='http:\/\/www.w3.org\/2000\/svg'%20viewBox='0%200%20800%20344'%3E%3C\/svg%3E\" data-sizes=\"(max-width: 800px) 100vw, 800px\" \/><img decoding=\"async\" src=\"data:image\/svg+xml,%3Csvg%20xmlns='http:\/\/www.w3.org\/2000\/svg'%20viewBox='0%200%20800%20344'%3E%3C\/svg%3E\" alt=\"Transparent\" width=\"800\" height=\"344\" data-src=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent.jpg\" data-srcset=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent.jpg 800w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent-300x129.jpg 300w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent-768x330.jpg 768w\" data-sizes=\"(max-width: 800px) 100vw, 800px\" loading=\"lazy\" \/>\n<\/picture>\n<noscript><picture class=\"aligncenter size-full wp-image-483\"><source type=\"image\/webp\" srcset=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent.jpg.webp 800w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent-300x129.jpg.webp 300w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent-768x330.jpg.webp 768w\" sizes=\"(max-width: 800px) 100vw, 800px\"\/><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent.jpg\" alt=\"Transparent\" width=\"800\" height=\"344\" srcset=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent.jpg 800w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent-300x129.jpg 300w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Transparent-768x330.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\"\/>\n<\/picture>\n<\/noscript><\/p>\n<hr\/>\n<h2 id=\"step-1-create-a-proxy-gateway\" class=\"ftwp-heading\"><span class=\"ez-toc-section\" id=\"Step_1_%E2%80%93_Create_a_Proxy_Gateway\"><\/span>Step 1 \u2013 Create a Proxy Gateway<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The first step is to set up a gateway on your server that will emulate what any other server will use to determine if you\u2019re using a proxy using the $_SERVER superglobal. Make sure this PHP file is accessible through a public URL (http:\/\/yourdomain.com\/gateway.php) Since $_SERVER outputs as an array, you\u2019ll need to do some formatting. Here is an example of how I formatted the output in gateway.php as a string to easily extract the data for the proxy anonymity tester:<\/p>\n<blockquote>\n<p>$output = \u201d;<br \/>\nforeach ($_SERVER as $key => $value) {<br \/>\nif (!empty($value)) {<br \/>\n$output .= $key . \u2018\u2013\u2018 . $value . \u2018\u2014\u2018;<br \/>\n}<br \/>\n}<br \/>\n$output = substr($output, 0, -3);<br \/>\ndie($output);<\/p>\n<\/blockquote>\n<hr\/>\n<h2 id=\"step-2-connect-to-the-server-gateway-and-retrieve-results\" class=\"ftwp-heading\"><span class=\"ez-toc-section\" id=\"Step_2_%E2%80%93_Connect_to_the_Server_Gateway_and_Retrieve_Results\"><\/span>Step 2 \u2013 Connect to the Server Gateway and Retrieve Results<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Once your gateway is set up, you\u2019re ready to connect to it with your proxy and retrieve the $_SERVER output which will reveal how anonymous the proxy is. Below is some simple PHP code using cURL to access your gateway URL (such as, yourdomain.com\/gateway.php). This simple cURL script will detect if your proxy\u2019s protocol is <a href=\"https:\/\/www.bestproxyreviews.com\/what-is-the-di%ef%ac%80erence-between-http-and-socks-proxies\/\">HTTP, SOCKS4, SOCKS5 or SOCKS4\/5<\/a>, so no need to determine that beforehand.<\/p>\n<p>Note: Make sure the $url variable is set to your gateway URL and the $proxy variable is set to the proxy you\u2019d like to test (in IP:PORT format).<\/p>\n<blockquote>\n<p>$types = array(<br \/>\n\u2018http&#8217;,<br \/>\n\u2018socks4&#8242;,<br \/>\n\u2018socks5&#8242;<br \/>\n);<br \/>\n$url = curl_init($url);<br \/>\ncurl_setopt($url, CURLOPT_PROXY, $proxy);<br \/>\nforeach ($types as $type) {<br \/>\nswitch ($type) {<br \/>\ncase \u2018http&#8217;:<br \/>\ncurl_setopt($url, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);<br \/>\nbreak;<br \/>\ncase \u2018socks4&#8242;:<br \/>\ncurl_setopt($url, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);<br \/>\nbreak;<br \/>\ncase \u2018socks5&#8242;:<br \/>\ncurl_setopt($url, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);<br \/>\nbreak;<br \/>\n}<br \/>\ncurl_setopt($url, CURLOPT_TIMEOUT, 10);<br \/>\ncurl_setopt($url, CURLOPT_RETURNTRANSFER, 1);<br \/>\n$resultsQuery = explode(\u2018\u2014\u2018, curl_exec($url));<br \/>\nif (!empty($resultsQuery)) {<br \/>\nbreak;<br \/>\n}<br \/>\n}<br \/>\n$results = array();<br \/>\nforeach ($resultsQuery as $result) {<br \/>\nif (!empty($result)) {<br \/>\n$split = explode(\u2018\u2013\u2018, $result);<\/p>\n<p>if (!empty($split[1])) {<br \/>\n$results[$split[0]] = $split[1];<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\ncurl_close($url);<br \/>\nunset($url);<br \/>\nreturn $results;<br \/>\n}<\/p>\n<\/blockquote>\n<hr\/>\n<h2 id=\"step-3-check-proxy-anonymity-by-using-the-gateway-results\" class=\"ftwp-heading\"><span class=\"ez-toc-section\" id=\"Step_3_%E2%80%93_Check_Proxy_Anonymity_by_Using_the_Gateway_Results\"><\/span>Step 3 \u2013 Check Proxy Anonymity by Using the Gateway Results<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><picture class=\"aligncenter size-full wp-image-482 perfmatters-lazy\" loading=\"lazy\"><source type=\"image\/webp\" data-srcset=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results.jpg.webp 800w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results-300x118.jpg.webp 300w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results-768x301.jpg.webp 768w\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns='http:\/\/www.w3.org\/2000\/svg'%20viewBox='0%200%20800%20314'%3E%3C\/svg%3E\" data-sizes=\"(max-width: 800px) 100vw, 800px\" \/><img decoding=\"async\" src=\"data:image\/svg+xml,%3Csvg%20xmlns='http:\/\/www.w3.org\/2000\/svg'%20viewBox='0%200%20800%20314'%3E%3C\/svg%3E\" alt=\"Check Proxy Anonymity by Using the Gateway Results\" width=\"800\" height=\"314\" data-src=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results.jpg\" data-srcset=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results.jpg 800w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results-300x118.jpg 300w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results-768x301.jpg 768w\" data-sizes=\"(max-width: 800px) 100vw, 800px\" loading=\"lazy\" \/>\n<\/picture>\n<noscript><picture class=\"aligncenter size-full wp-image-482\"><source type=\"image\/webp\" srcset=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results.jpg.webp 800w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results-300x118.jpg.webp 300w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results-768x301.jpg.webp 768w\" sizes=\"(max-width: 800px) 100vw, 800px\"\/><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results.jpg\" alt=\"Check Proxy Anonymity by Using the Gateway Results\" width=\"800\" height=\"314\" srcset=\"https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results.jpg 800w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results-300x118.jpg 300w, https:\/\/royadata.io\/blog\/wp-content\/uploads\/2023\/10\/Check-Proxy-Anonymity-by-Using-the-Gateway-Results-768x301.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\"\/>\n<\/picture>\n<\/noscript><\/p>\n<p>After you have the returned server data from the above gatewayResults function, simply pass it to the function below and it will return the proxy anonymity level.<\/p>\n<blockquote>\n<p>public function checkAnonymity($server = array()) {<br \/>\n$realIp = $_SERVER[\u2018REMOTE_ADDR&#8217;];<br \/>\n$level = \u2018transparent&#8217;;<br \/>\nif (!in_array($realIp, $server)) {<br \/>\n$level = \u2018anonymous&#8217;;<br \/>\n$proxyDetection = array(<br \/>\n\u2018HTTP_X_REAL_IP&#8217;,<br \/>\n\u2018HTTP_X_FORWARDED_FOR&#8217;,<br \/>\n\u2018HTTP_X_PROXY_ID&#8217;,<br \/>\n\u2018HTTP_VIA&#8217;,<br \/>\n\u2018HTTP_X_FORWARDED_FOR&#8217;,<br \/>\n\u2018HTTP_FORWARDED_FOR&#8217;,<br \/>\n\u2018HTTP_X_FORWARDED&#8217;,<br \/>\n\u2018HTTP_FORWARDED&#8217;,<br \/>\n\u2018HTTP_CLIENT_IP&#8217;,<br \/>\n\u2018HTTP_FORWARDED_FOR_IP&#8217;,<br \/>\n\u2018VIA&#8217;,<br \/>\n\u2018X_FORWARDED_FOR&#8217;,<br \/>\n\u2018FORWARDED_FOR&#8217;,<br \/>\n\u2018X_FORWARDED FORWARDED&#8217;,<br \/>\n\u2018CLIENT_IP&#8217;,<br \/>\n\u2018FORWARDED_FOR_IP&#8217;,<br \/>\n\u2018HTTP_PROXY_CONNECTION&#8217;,<br \/>\n\u2018HTTP_XROXY_CONNECTION&#8217;<br \/>\n);<br \/>\nif (!array_intersect(array_keys($server), $proxyDetection)) {<br \/>\n$level = \u2018elite&#8217;;<br \/>\n}<br \/>\n}<br \/>\nreturn $level;<br \/>\n}<\/p>\n<\/blockquote>\n<hr\/>\n<p>If you have any improvements, suggestions or questions about this tutorial on how to detect proxy anonymity using PHP, please feel free to leave a comment below.<\/p>\n<hr\/>\n<p>Related,<\/p>\n<ul>\n<li><a href=\"https:\/\/royadata.io\/blog\/rotating-proxies-api-with-curl\/\">How to Use Rotating Proxy API &#038; Proxy lists with CURL for data mining<\/a><\/li>\n<li><a href=\"https:\/\/royadata.io\/blog\/use-chrome-headless-and-dedicated-proxies-to-scrape-any-website\/\">Use Chrome Headless and Dedicated Proxies to Scrape Any Website<\/a><\/li>\n<li><a href=\"https:\/\/royadata.io\/blog\/how-to-detect-if-an-ip-address-is-a-proxy\/\">5 Ways to Detect if an IP Address is a Proxy<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>When building apps that involve scraping, downloading data and automation, staying completely anonymous can be a huge concern for developers. Although there are many di\ufb00erent proxy checkers out there, most of them all seem to deliver slightly di\ufb00erent and unreliable results. This guide will walk you through the three steps and provide a clean PHP &#8230; <a title=\"How to Detect Proxy Anonymity Level Using PHP\" class=\"read-more\" href=\"http:\/\/royadata.io\/blog\/php-detect-proxy-anonymity-level\/\" aria-label=\"More on How to Detect Proxy Anonymity Level Using PHP\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":481,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/royadata.io\/blog\/wp-json\/wp\/v2\/posts\/6302"}],"collection":[{"href":"http:\/\/royadata.io\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/royadata.io\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/royadata.io\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/royadata.io\/blog\/wp-json\/wp\/v2\/comments?post=6302"}],"version-history":[{"count":0,"href":"http:\/\/royadata.io\/blog\/wp-json\/wp\/v2\/posts\/6302\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/royadata.io\/blog\/wp-json\/wp\/v2\/media\/481"}],"wp:attachment":[{"href":"http:\/\/royadata.io\/blog\/wp-json\/wp\/v2\/media?parent=6302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/royadata.io\/blog\/wp-json\/wp\/v2\/categories?post=6302"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/royadata.io\/blog\/wp-json\/wp\/v2\/tags?post=6302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}