NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page CURL Class

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 11-12-2006, 12:41 PM THREAD STARTER               #1 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism

CURL Class


http://www.ruuma.com/s/class.curl.phps
????: NamePros.com http://www.namepros.com/code/257265-curl-class.html


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 by Dan; 03-24-2007 at 01:01 PM.
Dan is offline  
Old 11-20-2006, 12:33 PM   #2 (permalink)
NamePros Expert
 
IAmAllanShore's Avatar
Join Date: Nov 2004
Location: Esse quam videri
Posts: 8,332
IAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond repute
 

Member of the Month
January 2005Member of the Month
February 2007
Ethan Allen Fund Child Abuse Child Abuse Child Abuse Child Abuse Save The Children Save The Children Child Abuse Child Abuse Child Abuse Child Abuse VA Tech Memorial Child Abuse Child Abuse Child Abuse Child Abuse Child Abuse Child Abuse Child Abuse Child Abuse Child Abuse Child Abuse
Gotta be honest - I don't know what it does...

Any help for an ignorant fart?

-Allan
__________________

Something Witty This Way Comes...
IAmAllanShore is offline  
Old 11-20-2006, 04:04 PM THREAD STARTER               #3 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
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.
Dan is offline  
Old 11-20-2006, 05:40 PM   #4 (permalink)
NamePros Regular
 
Jim_'s Avatar
Join Date: Aug 2005
Location: NY, USA
Posts: 610
Jim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to behold
 


Save The Children
How is this better than just using the curl functions themselves?

Next time, use raw sockets.
__________________
ask me about the internet
Jim_ is offline  
Old 11-20-2006, 06:57 PM THREAD STARTER               #5 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
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);
Dan is offline  
Old 11-20-2006, 07:38 PM   #6 (permalink)
NamePros Expert
 
IAmAllanShore's Avatar
Join Date: Nov 2004
Location: Esse quam videri
Posts: 8,332
IAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond reputeIAmAllanShore has a reputation beyond repute
 

Member of the Month
January 2005Member of the Month
February 2007
Ethan Allen Fund Child Abuse Child Abuse Child Abuse Child Abuse Save The Children Save The Children Child Abuse Child Abuse Child Abuse Child Abuse VA Tech Memorial Child Abuse Child Abuse Child Abuse Child Abuse Child Abuse Child Abuse Child Abuse Child Abuse Child Abuse Child Abuse
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

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
__________________

Something Witty This Way Comes...
IAmAllanShore is offline  
Old 11-20-2006, 07:44 PM   #7 (permalink)
NamePros Regular
 
Jim_'s Avatar
Join Date: Aug 2005
Location: NY, USA
Posts: 610
Jim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to behold
 


Save The Children
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.
__________________
ask me about the internet
Jim_ is offline  
Old 11-20-2006, 09:44 PM   #8 (permalink)
NamePros Regular
 
kwan's Avatar
Join Date: Oct 2006
Location: Netherlands
Posts: 370
kwan is a jewel in the roughkwan is a jewel in the roughkwan is a jewel in the rough
 


Wildlife
Nice, but I use phpclasses.org for this stuff
kwan is offline  
Old 11-21-2006, 09:52 AM   #9 (permalink)
NamePros Regular
 
beaver6813's Avatar
Join Date: May 2005
Location: England
Posts: 392
beaver6813 is a jewel in the roughbeaver6813 is a jewel in the roughbeaver6813 is a jewel in the rough
 




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
beaver6813 is offline  
Old 11-21-2006, 11:56 AM   #10 (permalink)
Resistance is Futile
 
Kadenz's Avatar
Join Date: Apr 2006
Location: Montreal, Canada
Posts: 1,094
Kadenz is a name known to allKadenz is a name known to allKadenz is a name known to allKadenz is a name known to allKadenz is a name known to allKadenz is a name known to all
 



Wildlife Lou Gehrig's Disease (ALS)
Thanks Dan the Man!
I can do this with CURL any day, but this can sure help out some people new to PHP.
__________________
Freelance Web Developer
PHP, MySQL, XHTML, CSS, Javascript, jQuery, Wordpress
Portfolio: www.bundy.ca
Kadenz is offline  
Old 11-22-2006, 01:15 AM   #11 (permalink)
Formerly Array
 
-NB-'s Avatar
Join Date: Feb 2006
Location: San Diego, CA
Posts: 228
-NB- is a name known to all-NB- is a name known to all-NB- is a name known to all-NB- is a name known to all-NB- is a name known to all-NB- is a name known to all
 



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
-NB- is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 01:38 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger