Sometimes we face some situations when we need to execute a remote script with a proxy like:
- We don’t want to reveal our IP or location to the remote server
- IP is blocked on the remote server
- For testing of script/website for other countries
- and many more…
There could be countless reasons. I am not listing all of them here but instead, I’ll explain you in this tutorial how to execute a remote script through CURL and using a proxy connection.
You need a proxy IP/port to execute this script. You can find any free proxy on the web, just search the google.
<?php //This is the URL of the remote script that need to be executed $url = 'http://example.com/script.php'; // This is proxy IP $proxy_ip="xxx.xxx.xxx.xxx"; // This is proxy port $proxy_port="80"; $proxy = $proxy_ip.":".$proxy_port; // If the proxy require authentication, please uncomment below line and use correct username & password to authenticate the proxy //$proxyauth = 'user:password'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HEADER, 1); // return headers 0 no 1 yes curl_setopt($ch, CURLOPT_PROXY, $proxy); // If the proxy require authentication, please uncomment below line //curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:188.8.131.52) Gecko/20070914 Firefox/184.108.40.206"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); curl_close($ch); // Print the response of the script echo $result;