| | |||||
| ||||||||
| 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. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,796
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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.
|
| |
| | THREAD STARTER #3 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,796
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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. |
| |
| | THREAD STARTER #5 (permalink) |
| Buy my domains. Join Date: Feb 2006
Posts: 2,796
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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); |
| |
| | #6 (permalink) |
| NamePros Expert ![]() Join Date: Nov 2004 Location: Esse quam videri
Posts: 8,332
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | 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... |
| |
| | #7 (permalink) |
| NamePros Regular Join Date: Aug 2005 Location: NY, USA
Posts: 610
![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |
| | #9 (permalink) |
| NamePros Regular Join Date: May 2005 Location: England
Posts: 392
![]() ![]() ![]() | 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.com - Web Developer Extraordinaire! |
| |
| | #10 (permalink) |
| Resistance is Futile Join Date: Apr 2006 Location: Montreal, Canada
Posts: 1,094
![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |
| | #11 (permalink) |
| Formerly Array Join Date: Feb 2006 Location: San Diego, CA
Posts: 228
![]() ![]() ![]() ![]() ![]() ![]() | 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 |
| |