Home Backend Development PHP Tutorial In-depth explanation of PHP curl parameters_PHP tutorial

In-depth explanation of PHP curl parameters_PHP tutorial

Jul 21, 2016 pm 03:06 PM
curl php for parameter go deep of set up Detailed explanation transfer Options

curl_setopt
(PHP 4 >= 4.0.2)
curl_setopt -- 为CURL调用设置一个选项
描述
bool curl_setopt (int ch, string option, mixed value)
curl_setopt()函数将为一个CURL会话设置选项。option参数是你想要的设置,value是这个选项给定的值。

下列选项的值将被作为长整形使用(在option参数中指定):
CURLOPT_INFILESIZE: 当你上传一个文件到远程站点,这个选项告诉PHP你上传文件的大小。
CURLOPT_VERBOSE: 如果你想CURL报告每一件意外的事情,设置这个选项为一个非零值。
CURLOPT_HEADER: 如果你想把一个头包含在输出中,设置这个选项为一个非零值。
CURLOPT_NOPROGRESS: 如果你不会PHP为CURL传输显示一个进程条,设置这个选项为一个非零值。
注意:PHP自动设置这个选项为非零值,你应该仅仅为了调试的目的来改变这个选项。
CURLOPT_NOBODY: 如果你不想在输出中包含body部分,设置这个选项为一个非零值。
CURLOPT_FAILONERROR: 如果你想让PHP在发生错误(HTTP代码返回大于等于300)时,不显示,设置这个选项为一人非零值。默认行为是返回一个正常页,忽略代码。
CURLOPT_UPLOAD: 如果你想让PHP为上传做准备,设置这个选项为一个非零值。
CURLOPT_POST: 如果你想PHP去做一个正规的HTTP POST,设置这个选项为一个非零值。这个POST是普通的 application/x-www-from-urlencoded 类型,多数被HTML表单使用。
CURLOPT_FTPLISTONLY: 设置这个选项为非零值,PHP将列出FTP的目录名列表。
CURLOPT_FTPAPPEND: 设置这个选项为一个非零值,PHP将应用远程文件代替覆盖它。
CURLOPT_NETRC: 设置这个选项为一个非零值,PHP将在你的 ~./netrc 文件中查找你要建立连接的远程站点的用户名及密码。
CURLOPT_FOLLOWLOCATION: 设置这个选项为一个非零值(象 'Location: ')的头,服务器会把它当做HTTP头的一部分发送(注意这是递归的,PHP将发送形如 'Location: '的头)。
CURLOPT_PUT: 设置这个选项为一个非零值去用HTTP上传一个文件。要上传这个文件必须设置CURLOPT_INFILE和CURLOPT_INFILESIZE选项.
CURLOPT_MUTE: 设置这个选项为一个非零值,PHP对于CURL函数将完全沉默。
CURLOPT_TIMEOUT: 设置一个长整形数,作为最大延续多少秒。
CURLOPT_LOW_SPEED_LIMIT: 设置一个长整形数,控制传送多少字节。
CURLOPT_LOW_SPEED_TIME: 设置一个长整形数,控制多少秒传送CURLOPT_LOW_SPEED_LIMIT规定的字节数。
CURLOPT_RESUME_FROM: 传递一个包含字节偏移地址的长整形参数,(你想转移到的开始表单)。
CURLOPT_SSLVERSION: 传递一个包含SSL版本的长参数。默认PHP将被它自己努力的确定,在更多的安全中你必须手工设置。
CURLOPT_TIMECONDITION: 传递一个长参数,指定怎么处理CURLOPT_TIMEVALUE参数。你可以设置这个参数为TIMECOND_IFMODSINCE 或 TIMECOND_ISUNMODSINCE。这仅用于HTTP。
CURLOPT_TIMEVALUE: 传递一个从1970-1-1开始到现在的秒数。这个时间将被CURLOPT_TIMEVALUE选项作为指定值使用,或被默认TIMECOND_IFMODSINCE使用。

The values ​​of the following options will be treated as strings:
CURLOPT_URL: This is the URL address you want to retrieve using PHP. You can also set this option during initialization with the curl_init() function.
CURLOPT_USERPWD: Pass a string in the form of [username]:[password] and use PHP to connect.
CURLOPT_PROXYUSERPWD: Pass a string in the format [username]:[password] to connect to the HTTP proxy.
CURLOPT_RANGE: Pass a range you want to specify. It should be in 'X-Y' format, with X or Y being excluded. HTTP transfers also support several intervals, separated by commas (X-Y,N-M).
CURLOPT_POSTFIELDS: Pass a string containing all the data as an HTTP "POST" operation.
CURLOPT_REFERER: A string containing a 'referer' header in the HTTP request.
CURLOPT_USERAGENT: A string containing a 'user-agent' header in the HTTP request.
CURLOPT_FTPPORT: Pass an IP address containing the IP address used by the ftp 'POST' command. This POST command 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 '-' (use the system default IP address).
CURLOPT_COOKIE: Pass a header connection containing an HTTP cookie.
CURLOPT_SSLCERT: Pass a string containing the certificate in PEM format.
CURLOPT_SSLCERTPASSWD: Pass a password containing the necessary password to use the CURLOPT_SSLCERT certificate.
CURLOPT_COOKIEFILE: Pass a string containing the name of the file containing cookie data. This cookie file can be in Netscape format, or it can be a stack of HTTP-style headers stored in the file.
CURLOPT_CUSTOMREQUEST: When making an HTTP request, pass a character to be used by GET or HEAD. 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: Don't do this before making sure your server supports the command.

The following options require a file description (obtained using the fopen() function):
CURLOPT_FILE: This file will be the output file you place the transfer to. The default is STDOUT.
CURLOPT_INFILE: This file is the input file you sent.
CURLOPT_WRITEHEADER: This file contains the header part of your output.
CURLOPT_STDERR: This file has errors written instead of stderr.
Example code: Tested

Copy code The code is as follows:

@header( "Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
@header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// always modified
@header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
@header("Cache -Control: post-check=0, pre-check=0", false);
@header("Pragma: no-cache");
@header("content-type:text/html; charset =utf-8");
$url = 'http://s.jb51.net';
$querystring = $_SERVER["QUERY_STRING"];
$currentUrl = $_SERVER['SERVER_NAME '];
if($querystring != '') $querystring = $querystring . "&";
$querystring = $querystring . "SiteURL=" . $currentUrl;
if($querystring ! = '')
{
$url = $url . "?" . $querystring;
}
$ch = curl_init();
$timeout = 60; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$handles = curl_exec($ch);
//The following are replacements, which can be combined with server pseudo-static settings
$handles = preg_replace("/?page=([0-9]+)&categoryId=([0-9 ]+)/i","/fenlei/category-$1-$2.html",$handles);
$handles = preg_replace("/?categoryId=([0-9]+)/i"," /fenlei/category--$1.html",$handles);
$handles = preg_replace("/?page=([0-9]+)/i","/fenlei/category-$1.html" ,$handles);
$handles = preg_replace("/infodetail.aspx?ID=([0-9]+)/i","/fenlei/$1.html",$handles);
$ handles = str_replace("infolist.aspx","/fenlei/index.html",$handles);
$handles = str_replace("unionlist.aspx","unionlist.html",$handles);
echo $handles;
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/327599.htmlTechArticlecurl_setopt (PHP 4 = 4.0.2) curl_setopt -- Set an option description for CURL call bool curl_setopt (int ch , string option, mixed value) The curl_setopt() function will set up a CURL session...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles