SmexyyWeby

Scripting for Fun and Passion

Setting Up cURL proxy in XAMPP


cURL is a really nice tool to transfer data to and from a web server. You can use it to access URL and get the contents of web page via a php script.

XAMPP comes with cURL installed but you need to enable it in the php.ini file.

For this go to your XAMPP folder. (I have it installed in C:\xampp\)

  • Go to php folder
  • Open php.ini
  • Search for this line ;extension=php_curl.dll
  • Remove the ; in the beginning (; is used to comment lines)
  • Save the file. (Make sure you do not have apache running at this moment otherwise you can’t save the file. Or best is to open it as an administrator for editing)
  • Restart apache from XAMPP Control Panel.
  • Reopen a cURL script in the browser.

Now sometimes we need to use cURL with a proxy so here is a sample code:

<?php

class cURL{
var $crl;

var $proxy_url;

var $proxy_username_pass;
function cURL($proxy_url="", $proxy_username_pass=""){

$this->proxy_url=$proxy_url;

$this->proxy_username_pass=$proxy_username_pass;

$this->crl = curl_init();

curl_setopt($this->crl, CURLOPT_PROXY, $this->proxy_url);

curl_setopt($this->crl, CURLOPT_PROXYUSERPWD, $this->proxy_username_pass);

}
function get_url_contents($url){

$crl=$this->crl;

$timeout = 5;

curl_setopt ($crl, CURLOPT_URL,$url);

curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);

$ret = curl_exec($crl);

curl_close($crl);

return $ret;

}

}
$proxy_url="http://proxy.com";

$proxy_username_pass="hello:hello";

$cObj=new cURL($proxy_url, $proxy_username_pass);

$webContent= $cObj->get_url_contents("https://smexyyweby.wordpress.com");

echo $webContent;
?>

This will open the page https://smexyyweby.wordpress.com in your browser.Also you have the whole source code of the webpage saved in $webContent so that you can use it accordingly.

Please post any queries or improvements.

Advertisements

One response to “Setting Up cURL proxy in XAMPP

  1. Pingback: Javascript of Revolving Images Spam on Facebook | SmexyyWeby

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: