PHP USES curl to simulate user login code

  • 2020-03-31 21:16:58
  • OfStack

Bool curl_setopt (int ch, string option, mixed value)

The curl_setopt() function sets options for an CURL session. The option parameter is the setting you want, and the value is the value given by the option.

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

*CURLOPT_INFILESIZE: when you upload a file to a remote site, this option tells PHP the size of the file you upload.
*CURLOPT_VERBOSE: if you want CURL to report every unexpected occurrence, set this option to a non-zero value.
*CURLOPT_HEADER: if you want to include a header in the output, set this option to a non-zero value.
*CURLOPT_NOPROGRESS: if you don't know PHP to display a process bar for the CURL transfer, set this option to a non-zero value.

Note: PHP automatically sets this option to a non-zero value. You should change this option only for debugging purposes.

*CURLOPT_NOBODY: if you do not want to include the body part in the output, set this option to a non-zero value.
*CURLOPT_FAILONERROR: if you want PHP not to show when an error occurs (HTTP code returns greater than or equal to 300), set this option to a one-person non-zero value. The default behavior is to return a normal page and ignore the code.
*CURLOPT_UPLOAD: if you want PHP to prepare for an upload, set this option to a non-zero value.
*CURLOPT_POST: if you want PHP to do a regular HTTP POST, set this option to a non-zero value. This POST is of a normal application/x-www-from-urlencoded type, most used by HTML forms.
*CURLOPT_FTPLISTONLY: set this option to a non-zero value, and PHP will list the directory names for FTP.
*CURLOPT_FTPAPPEND: set this option to a non-zero value, and PHP will apply the remote file instead of overwriting it.
*CURLOPT_NETRC: set this option to a non-zero value, and PHP will look in your ~./netrc file for the username and password of the remote site you want to connect to.
*CURLOPT_FOLLOWLOCATION: set this option to a non-zero value (like "Location:") that the server will send as part of the HTTP header (note that this is recursive; PHP will send a header like "Location:").
*CURLOPT_PUT: set this option to a non-zero value to upload a file using HTTP. To upload this file you must set the CURLOPT_INFILE and CURLOPT_INFILESIZE options.
*CURLOPT_MUTE: set this option to a non-zero value, and PHP will be completely silent about CURL.
*CURLOPT_TIMEOUT: sets the number of long shapers as the maximum duration of seconds.
*CURLOPT_LOW_SPEED_LIMIT: sets the number of bytes to be transferred.
*CURLOPT_LOW_SPEED_TIME: sets the number of bytes to be transferred in seconds.
*CURLOPT_RESUME_FROM: passes a long-shaping parameter that contains a byte offset address (the start form you want to move to).
*CURLOPT_SSLVERSION: passes a long parameter that contains the SSL version. The default PHP will be determined by its own efforts, in more security you have to set manually.
*CURLOPT_TIMECONDITION: passes a long parameter that specifies what to do with the CURLOPT_TIMEVALUE parameter. You can set this parameter to TIMECOND_IFMODSINCE or TIMECOND_ISUNMODSINCE. This is for HTTP only.
*CURLOPT_TIMEVALUE: passes a number of seconds from the start of 1970-1-1 to the present. This time will be used by the CURLOPT_TIMEVALUE option as the specified value, or by the default TIMECOND_IFMODSINCE.

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

*CURLOPT_URL: this is the URL you want to get back in PHP. You can also set this option when initializing with the curl_init() function.
*CURLOPT_USERPWD: passes a string in the form of [username]:[password] style to connect with PHP.
*CURLOPT_PROXYUSERPWD: pass a string in the form of [username]:[password] to connect to the HTTP proxy.
*CURLOPT_RANGE: passes a range you want to specify. It should be in the "x-y" format, with the exception of X or Y. HTTP transport also supports several intervals, separated by funny sentences (x-y, n-m).
*CURLOPT_POSTFIELDS: passes a string of all data as an HTTP "POST" operation.
*CURLOPT_REFERER: a string that contains a "referer" header in an HTTP request.
*CURLOPT_USERAGENT: a string containing a "user-agent" header in an HTTP request.
*CURLOPT_FTPPORT: passes an IP address containing the IP address used by the FTP "POST" directive. The POST directive tells the remote server to connect to the IP address we specified. The string can be an IP address, a hostname, a network interface name (in UNIX), or '-'(using the system's default IP address).
*CURLOPT_COOKIE: passes a header connection containing an HTTP cookie.
*CURLOPT_SSLCERT: passes a string containing the PEM format certificate.
*CURLOPT_SSLCERTPASSWD: pass a password containing the required password to use the CURLOPT_SSLCERT certificate.
*CURLOPT_COOKIEFILE: a string that passes the name of the file containing cookie data. The cookie file can be either in Netscape format or an HTTP style header in the heap stored in the file.
*CURLOPT_CUSTOMREQUEST: when making an HTTP request, pass a character to be used by GET or HEAD. For DELETE or other operations is beneficial, more Pass a string to be used instead of GET or HEAD when doing an HTTP request. This is useful for doing or another, more obscure, HTTP request.

Note: do not do this until you are sure that your server supports the command.

The following options require a file description (obtained by using the fopen() function) :

*CURLOPT_FILE: this file will be the output file that you put forward. The default is STDOUT.
*CURLOPT_INFILE: this file is the input file you sent.
*CURLOPT_WRITEHEADER: this file contains the header of your output.
*CURLOPT_STDERR: this file has an error instead of stderr.

An example of a page that needs to be logged in. The current practice is to log in every time, maybe once.

Example:
 
<?php 
 $cookie_jar = tempnam( ' ./tmp', ' cookie'); 
 $ch = curl_init(); 
curl_setopt( $ch, CURLOPT_URL,  ' http://www.QQView.com'); 
curl_setopt( $ch, CURLOPT_POST, 1); 
 $request =  ' email_address=&password=&action='; 
curl_setopt( $ch, CURLOPT_POSTFIELDS,  $request); 
//Save the returned cookie information in   $cookie_jar file
curl_setopt( $ch, CURLOPT_COOKIEJAR,  $cookie_jar); 
//Sets whether the returned data is automatically displayed
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); 
//Sets whether to display header information
curl_setopt( $ch, CURLOPT_HEADER, false); 
//Sets whether to output the page content
curl_setopt( $ch, CURLOPT_NOBODY, false); 
curl_exec( $ch); 
curl_close( $ch); 
//get data after login 
 $ch2 = curl_init(); 
curl_setopt( $ch2, CURLOPT_URL,  ' http://*****'); 
curl_setopt( $ch2, CURLOPT_HEADER, false); 
curl_setopt( $ch2, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt( $ch2, CURLOPT_COOKIEFILE,  $cookie_jar); 
 $orders = curl_exec( $ch2); 
echo  ' <pre>'; 
echo strip_tags( $orders); 
echo  ' </pre>'; 
curl_close( $ch2); 
?> 

Related articles: