Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

CURL Class

SpaceshipSpaceship
NamecheapNamecheap
Namecheap AuctionsNamecheap Auctions
Watch

Dan

Buy my domains.VIP Member
Impact
108
http://www.ruuma.com/s/class.curl.phps :lala:


Code:
Usage

Include this script from a different file.
  include('class.curl.php');

Set the referrer:
  $curl->set_referrer('http://google.com');

Set the user agent:
  (for firefox 2.0 on windows xp)
  $curl->set_user_agent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0');

Set the error message:
  $curl->set_error_message('An error occured.');

Get request:
  $data = $curl->get('http://site.com/file.php?var=value&var2=value');

Post request:
  $curl->post('http://site.com/file.php', 'var=value&var2=value');

Using an array for post variables:
  $postvalues = array("var"  => "value",
                      "var2" => "value");
  $curl->post_array('http://site.com/file.php', $postvalues);


Rep is appreciated. _\|/_
 
Last edited:
2
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Gotta be honest - I don't know what it does...

Any help for an ignorant fart? ;)

-Allan :gl:
 
0
Close
It can download or send information to/from other pages.

To login to a form that had:
action="http://site.com/login.php" method="post"
and the fields username and password, you would do:
$curl->post('http://site.com/login.php', 'username=yourusername&password=yourpassword');

Also, some hosts don't allow you to use file_get_contents or fopen, so this is a way to get around that.
 
0
Close
How is this better than just using the curl functions themselves?

Next time, use raw sockets. :P
 
0
Close
The point is to make it very easy to use curl. You can use $curl->get('url'); instead of the 10 or so lines it would take to do it without the functions. It's a lot easier to set the referrer and the other options with $curl->set_referrer('url'); rather than curl_setopt($this->ch, CURLOPT_REFERER, $referrer_url);
 
1
Close
I love you guys ;)

It's like watching an old KungFu movie where I don't know the language, but they're still speaking English :tu:

Dan, still don't get what it does, but that's a failing on my part, not yours. Best to you, and I can tell that you're light-years ahead of me on the code ;)

-Allan :gl:
 
0
Close
Basicly, it allows you to make GET and POST requests to other web pages and get the result.

Example usage: you could make a script that POST's a username and password to a login page somewhere, and return the resulting page.
 
0
Close
Nice, but I use phpclasses.org for this stuff :)
 
0
Close
Thanks Dan, cool script :) Could be very useful for login scripts and proxy sites etc ^^ Submit it to phpclasses.org to get some more viewers :)
 
0
Close
Thanks Dan the Man!
I can do this with CURL any day, but this can sure help out some people new to PHP.
 
0
Close
Nice contribution. I am experienced with PHP, and I can tell you that this will definitely help when I use cURL. It gets to be a pain redefining it all, so this will really condense the code.

Definite +rep!!

Nick
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

A browser tab with a favicon next to the page title
Search members
You can now search for members by name, company, location and more. Open the search at the top of any page and choose Members. You will...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back