PHP's curl____php

Source: Internet
Author: User
Tags curl http cookie http post

Have not noticed this dongdong, today saw someone mentioned, so learn a bit.

First is the configuration, to the php.ini inside the Extension=php_curl.dll open, put Php_curl.dll, Ssleay32.dll,libeay32.dll put under System32. Run the example in the manual.

<?php

$ch = Curl_init ("http://www.example.com/");

$fp = fopen ("Example_homepage.txt", "w");

curl_setopt ($ch, Curlopt_file, $fp);

curl_setopt ($ch, Curlopt_header, 0);

Curl_exec ($ch);

Curl_close ($ch);

Fclose ($FP);

?>

OK, generate file Example_homepage.txt. The handbook is full of English and has a big head. When you use this stuff, it's really rare.

On the Curl supplement:

The Curl Library in PHP

Curl_close-Closes a curl session

Curl_copy_handle-Copies all the contents and parameters of a Curl connection resource

Curl_errno-Returns a numeric number containing the current session error message

Curl_error-Returns a string containing the current session error message

Curl_exec-Perform a curl session

Curl_getinfo-Get information on a Curl connection resource handle

Curl_init-Initialization of a curl session

Curl_multi_add_handle-Add a separate curl handle resource to the Curl batch session

Curl_multi_close-Closes a batch handle resource

Curl_multi_exec-Parsing a curl batch handle

Curl_multi_getcontent-Returns the text stream of the obtained output

Curl_multi_info_read-Gets the relevant transport information for the currently resolved curl

Curl_multi_init-Initializes a curl batch handle resource

Curl_multi_remove_handle-Remove a handle resource from a curl batch handle resource

Curl_multi_select-get the sockets associated with the curl extension, which can then to be "selected"

Curl_setopt_array-set session parameters as an array for a curl

curl_setopt-set session parameters for a curl

Curl_version-Get Curl-related version of the letter

The Curl_init () function Initializes a curl session, and the only parameter to the Curl_init () function is optional, representing a URL address.

The Curl_exec () function is to execute a curl session, the only argument is the handle returned by the Curl_init () function.

The role of the Curl_close () function is to close a curl session, with the only argument being a handle returned by the Curl_init () function.

Seemingly this thing is very powerful, the original brush Dongdong can also use it oh. Find examples from the Internet. Hey, not original OH.

2, Brush the building:

Set_time_limit (0);
Set Program Execution Time Unlimited
$i = 10000;
Played 10,000 times.
for ($j =0; $j &lt; $i; $j + +)
{

$URL = "http://www.yoururl.com/bbs/savepost.asp";
This address is the URL address of the action in the reply form.
$ch = Curl_init ();

curl_setopt ($ch, Curlopt_url, $URL);

curl_setopt ($ch, Curlopt_referer, "http://www.hxfoods.com/bbs/dispbbs.asp?boardid=14&amp;replyid=672709& amp;id=127437&amp;page=1&amp;skin=0&amp; Star=53 ");
Set the source address, if not set, the forum server may have authentication does not allow reply
curl_setopt ($ch, curlopt_cookiesession,true);
Can save cookies
curl_setopt ($ch, Curlopt_cookie, "dvforum=userid=24122&amp;usercookies=0&amp;userhidden=2&amp; password=w0reu3g775vry745&amp;userclass=%96%7c&amp;username=%a1%fa%a1%fa%b8%d2%cb%c0%b6%d3%a1%fa& Amp statuserid=2194783945 ");
Here's the cookie set.
curl_setopt ($ch, curlopt_post,1);
curl_setopt ($ch, curlopt_nobody,1);
Do not display content, because there are many forum replies to automatically jump.
curl_setopt ($ch, Curlopt_postfields, ' body=gfdfgdfgasdfgdfgdfgdfg&amp; followup=672709&amp; rootid=127437&amp;star=58&amp; totalusetable=dv_bbs3&amp; Amp username=→→ death squads →&amp;signflag=1&amp;total=65535 ');
Assign the parameters of the reply form that you analyzed to the individual values
curl_setopt ($ch, curlopt_header,true);
Curl_exec ($ch);
if (Curl_errno ($ch))
{
Print Curl_error ($ch);
}
Else
{
Curl_close ($ch);
}

}

Hey, and then paste point another study, dongdong a lot, see not come over, or paste it first here. Later, the information can be easily found.

Three settings for the curl_setopt () function

BOOL curl_setopt (INT-ch, string option, mixed value)

The curl_setopt () function sets the option for a curl session. The option parameter is the setting you want, and value is the values given by this choice.


The values of the following options will be used as long reshaping (specified in the option argument):

* Curlopt_infilesize: When you upload a file to a remote site, this option tells PHP the size of the file you uploaded.
* Curlopt_verbose: If you want to curl report every unexpected thing, set this option to a value other than 0.
* Curlopt_header: If you want to include a header in the output, set this option to a value other than 0.
* Curlopt_noprogress: If you don't have PHP to display a process bar for curl transmission, set this option to a non 0 value. Note: PHP automatically sets this option to a value other than 0, and you should only change this option for debugging purposes.
* Curlopt_nobody: If you do not want to include the body part in the output, set this option to a value other than 0.
* Curlopt_failonerror: If you want PHP to be in error (HTTP code returns greater than or equal to 300), do not display, set this option to a person not 0 value. The default behavior is to return a normal page, ignoring the code.
* Curlopt_upload: If you want PHP to be ready for upload, set this option to a value other than 0.
* Curlopt_post: If you want PHP to do a regular HTTP POST, set this option to a non 0 value. This post is an ordinary application/x-www-from-urlencoded type, most of which is used by HTML forms.
* Curlopt_ftplistonly: Set this option to a value other than 0, PHP lists the list of directory names for FTP.
* Curlopt_ftpappend: Set this option to a value other than 0, PHP will apply the remote file instead of overwriting it.
* CURLOPT_NETRC: Set this option to a value other than 0, PHP will find the user name and password of the remote site you want to connect to in your ~./netrc file.
* Curlopt_followlocation: Set this option to a non 0 value (like "Location:"), the server will send it as a part of the HTTP header (note that this is recursive, PHP will send the shape as "Location:" the head).
* Curlopt_put: Set this option for a non 0 value to upload a file with HTTP. To upload this file, you must set the Curlopt_infile and Curlopt_infilesize options.
* Curlopt_mute: Set this option to a non 0 value, PHP for the Curl function will be completely silent.
* Curlopt_timeout: Set a long shaping number, as the maximum continuation of how many seconds.
* Curlopt_low_speed_limit: Set a long shaping number to control how many bytes are transferred.
* Curlopt_low_speed_time: Set a long shaping number, control the number of seconds to transfer curlopt_low_speed_limit specified bytes.
* Curlopt_resume_from: Pass a long shaping parameter that contains the byte offset address (the start form you want to transfer to).
* Curlopt_sslversion: Passes a long parameter that contains an SSL version. The default PHP will be determined by its own efforts, and in more security you must set it manually.
* Curlopt_timecondition: Pass a long parameter, specify how to handle curlopt_timevalue parameters. You can set this parameter to Timecond_ifmodsince or timecond_isunmodsince. This is for HTTP only.
* Curlopt_timevalue: Passing a number of seconds from 1970-1-1 onwards to now. This time is used by the Curlopt_timevalue option as the specified value or by default timecond_ifmodsince.

The values of the following options will be used as strings:

* Curlopt_url: This is the URL you want to retrieve with PHP. You can also set this option when initializing with the Curl_init () function.
* Curlopt_userpwd: Pass a string that is shaped like [Username]:[password] style, function PHP to connect.
* Curlopt_proxyuserpwd: Passes a string in the form of a [Username]:[password] format to connect to the HTTP proxy.
* Curlopt_range: Pass a range you want to specify. It should be "XY" format, X or Y is excepted. HTTP transmissions also support several intervals, separated by a x-y,n-m.
* Curlopt_postfields: A string that passes all data as an HTTP "POST" operation.
* Curlopt_referer: Contains a string of "REFERER" headers in the HTTP request.
* Curlopt_useragent: Contains a string of "user-agent" headers in the HTTP request.
* Curlopt_ftpport: Passes an IP address that contains the FTP "POST" instruction. This post instruction tells the remote server to connect to the IP address we specified. This string can be an IP address, a host name, a network interface name (under Unix), or '-' (using the system default IP address).
* Curlopt_cookie: Passes a header connection that contains an HTTP COOKIE.
* Curlopt_sslcert: Passes a string containing the PEM format certificate.
* CURLOPT_SSLCERTPASSWD: Pass a password that is required to use the Curlopt_sslcert certificate.
* Curlopt_cookiefile: A string that passes the name of a file containing cookie data. This cookie file can be in Netscape format, or in the HTTP style header that is stockpiled in the file.
* Curlopt_customrequest: When making an HTTP request, pass a character to be used by get or head. It is useful for delete or other operations, more pass a string of used instead of a and head when doing a HTTP request. This is useful to doing or another, more obscure, HTTP request. Note: Do not do this before confirming your server support command. The following options require a file description (obtained by using the fopen () function):
* Curlopt_file: This file will be the output file where you place the transfer, default is stdout.
* Curlopt_infile: This file is the input file you sent over.
* Curlopt_writeheader: This file is written with the head part of your output.
* Curlopt_stderr: This file is written with errors rather than STDERR. To get an example of a page that needs to be logged in, the current practice is to log in once every time, and the person who needs it will improve.


Four related examples


1 examples
$cookie _jar = Tempnam ('. tmp ', ' Cookie ');

$ch = Curl_init (); curl_setopt ($ch, Curlopt_url, ' http://****** ');

curl_setopt ($ch, Curlopt_post, 1);

$request = ' email_address=&password=&action= ';

curl_setopt ($ch, Curlopt_postfields, $request);

Save the returned cookie information in the $cookie_jar file

curl_setopt ($ch, Curlopt_cookiejar, $cookie _jar);

Sets whether the returned data is automatically displayed

curl_setopt ($ch, Curlopt_returntransfer, 1);

Set whether to display header information

curl_setopt ($ch, Curlopt_header, false);

Set whether to output page content

curl_setopt ($ch, Curlopt_nobody, false);

Curl_exec ($ch);

Curl_close ($ch); Get data after Login

$ch 2 = Curl_init ();

curl_setopt ($ch 2, Curlopt_url, ' http://***** ');

curl_setopt ($ch 2, Curlopt_header, false);

curl_setopt ($ch 2, Curlopt_returntransfer, 1);

curl_setopt ($ch 2, Curlopt_cookiefile, $cookie _jar);

$orders = Curl_exec ($ch 2);

Echo ';

echo Strip_tags ($orders);

Echo ';

Curl_close ($ch 2);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.