search
How PHP extends CURLMar 27, 2018 am 11:21 AM
curlphpExpand

CURL is a file transfer tool that uses URL syntax to work in command line mode. It supports many protocols. It supports authentication functionality. It is commonly used in php to implement more complex transmission functions.

Functions implemented:

1. Realize remote acquisition and content collection

2. Realize FTP upload and download of PHP web version

3. Realize simulation Log in: Go to an email system, curl can simulate cookies

4, implement interface docking (API), data transmission, etc.: send text messages through a platform, capture and transfer the transmitted information.

5. Implement simulated cookies, etc.: Some attributes can only be operated when logged in.

How to use the CURL function:

By default, PHP does not support CURL. You need to enable this function in php.ini

;extension Remove the semicolon in front of =php_curl.dll

1 The first step in the entire operation process is to initialize with the cur_init() function

?

$curl = curl_init(‘www.php.cn')

3. After setting, Execute the transaction curl_exec($curl); 2. Use the curl_setopt() function to set options.

4 Finally close curl_close();

Use PHP CURL to implement transmission and acquisition functions (post transmission method): obtain remote web page data

$user = "admin";
$pass = "admin";
$curlPost= "user=$user&pass=$pass";
$ch = curl_init(); //初始化一个CURL对象
curl_setopt($ch, CURLOPT_URL,"http://localhost/edu/login.php");
//设置你所需要抓取的URL
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
//设置curl参数,要求结果是否输出到屏幕上,为true的时候是不返回到网页中
假设上面的0换成1的话,那么接下来的$data就需要echo一下。
curl_setopt($ch, CURLOPT_POST, 1);
//post提交
curl_setopt($ch, CURLOPT_POSTFIELDS,$curlPost);
$data = curl_exec($ch);
//运行curl,请求网页。
curl_close($ch);
[/code]

Realize remote simulation Log in to the most basic part.

curl still needs to configure the user name and password, but it is hidden by the browser.

============================================== ================================\

curl simulated login

Simulated login: You can still view the corresponding information even without logging in to the php100 forum.

Analyze login fields--->Keep cookies after logging in-->Read cookies and jump to relevant pages-->Catch number

1. After simulating login Create a file to save the cookie content

2. Simulate user login status by reading the generated cookie content

3. Go to the relevant page to obtain the required content

tempnameCreate a temporary File

tempnam() function creates a temporary file with a unique file name. If successful, the function returns the new temporary file name. On failure, returns false.

tempnam(dir,prefix)

Parameter Description

dir Required. Specifies the directory where temporary files are created.

prefix required. Specifies the beginning of the file name.

Equivalent to fopen → fwirte → fclose

It can return a Boolean value. It is very dangerous to use a third party to log in to your QQ and msn, because it can record your login status and capture your username and password.

Use CURL to simulate logging in to the PHP100 forum

1. Analyze the field name and number of required fields in the input box required for login

2. Save the cookie and obtain the number of member gold coins after simulating login.

Code:

//初始化一个 cURL 对象
$curl = curl_init();
//设置你需要抓取的URL
curl_setopt($curl, CURLOPT_URL," http://www.baidu.com ");
//设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 0);
//运行cURL,请求网页
$data = curl_exec($curl);
//关闭URL请求
curl_close($curl);
$user = "admin";
$pass = "admin100";
$curlPost= "user=$user&pass=$pass";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL," http://localhost/curl/login.php ");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$curlPost);
$data = curl_exec($ch);
curl_close($ch);
?>
if($_POST['user']=="admin"){
 echo"";
}else{
 echo"";
}
//print_r($_POST);
?>

Related recommendations:

Detailed explanation of the usage of PHP extension CURL


The above is the detailed content of How PHP extends CURL. For more information, please follow other related articles on the PHP Chinese website!

Statement
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
python中CURL和python requests的相互转换如何实现python中CURL和python requests的相互转换如何实现May 03, 2023 pm 12:49 PM

curl和Pythonrequests都是发送HTTP请求的强大工具。虽然curl是一种命令行工具,可让您直接从终端发送请求,但Python的请求库提供了一种更具编程性的方式来从Python代码中发送请求。将curl转换为Pythonrequestscurl命令的基本语法如下所示:curl[OPTIONS]URL将curl命令转换为Python请求时,我们需要将选项和URL转换为Python代码。这是一个示例curlPOST命令:curl-XPOSThttps://example.com/api

Linux下更新curl版本教程!Linux下更新curl版本教程!Mar 07, 2024 am 08:30 AM

在Linux下更新curl版本,您可以按照以下步骤进行操作:检查当前curl版本:首先,您需要确定当前系统中安装的curl版本。打开终端,并执行以下命令:curl--version该命令将显示当前curl的版本信息。确认可用的curl版本:在更新curl之前,您需要确定可用的最新版本。您可以访问curl的官方网站(curl.haxx.se)或相关的软件源,查找最新版本的curl。下载curl源代码:使用curl或浏览器,下载您选择的curl版本的源代码文件(通常为.tar.gz或.tar.bz2

php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

PHP8.1发布:引入curl多个请求并发处理PHP8.1发布:引入curl多个请求并发处理Jul 08, 2023 pm 09:13 PM

PHP8.1发布:引入curl多个请求并发处理近日,PHP官方发布了最新版本的PHP8.1,其中引入了一个重要的特性:curl多个请求并发处理。这个新特性为开发者提供了一个更加高效和灵活的方式来处理多个HTTP请求,极大地提升了性能和用户体验。在以往的版本中,处理多个请求往往需要通过创建多个curl资源,并使用循环来分别发送和接收数据。这种方式虽然能够实现目

从头到尾:如何使用php扩展cURL进行HTTP请求从头到尾:如何使用php扩展cURL进行HTTP请求Jul 29, 2023 pm 05:07 PM

从头到尾:如何使用php扩展cURL进行HTTP请求引言:在Web开发中,经常需要与第三方API或其他远程服务器进行通信。而使用cURL进行HTTP请求是一种常见而强大的方式。本文将介绍如何使用php扩展cURL来执行HTTP请求,并提供一些实用的代码示例。一、准备工作首先,确保php已安装cURL扩展。可以在命令行执行php-m|grepcurl查

linux curl是什么linux curl是什么Apr 20, 2023 pm 05:05 PM

在linux中,​curl是一个非常实用的、用来与服务器之间传输数据的工具,是一个利用URL规则在命令行下工作的文件传输工具;它支持文件的上传和下载,是综合传输工具。curl提供了一大堆非常有用的功能,包括代理访问、用户认证、ftp上传下载、HTTP POST、SSL连接、cookie支持、断点续传等等。

PHP Curl中如何处理网页的 301 重定向?PHP Curl中如何处理网页的 301 重定向?Mar 08, 2024 am 11:36 AM

PHPCurl中如何处理网页的301重定向?在使用PHPCurl发送网络请求时,时常会遇到网页返回的301状态码,表示页面被永久重定向。为了正确处理这种情况,我们需要在Curl请求中添加一些特定的选项和处理逻辑。下面将详细介绍在PHPCurl中如何处理网页的301重定向,并提供具体的代码示例。301重定向处理原理301重定向是指服务器返回了一个30

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

See all articles

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

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment