Table of Contents
回复讨论(解决方案)

curl函数

Jun 23, 2016 pm 02:12 PM
curl function

Curl PHP

function search($url,$curlPost){
$cookiejar = realpath ( 'cookie.txt' );
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url);
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $curlPost );
curl_setopt ( $ch, CURLOPT_COOKIEJAR, $cookiejar ); // 要回传cookie
$data=curl_exec ( $ch );
curl_close ( $ch );
return $data;
 }
?>

我想用PHP实现外网机器通过我的电脑访问内网的资源,一张截图是我在内网登录内网的网站的数据交互截图,另一张是通过我的PHP文件用curl函数访问时的截图,它提示少了什么文件。请问有人知道怎么解决吗

回复讨论(解决方案)

你仅仅模拟一个页面是不可以的,你现在只是模拟的login!checkLogin.action,要在这个内容中将header.html等替换成你用curl获取的连接,然后用curl获取内容展现出来,也就是header.html要变成curl.php?page=header.html。
如果你不替换的话,是在你模拟curl的php的同目录下找header.html,我估计肯定不存在。

你好,那你能告诉我怎么实现吗

仅仅用你那个 search 函数是完成不了了
从截图上看,你那是个框架页面,你只向外网返回了框架布局页数据,并没有向外网返回每一个框架页的数据

你这个应用应写成一个代理(proxy)程序才行

我向第一个界面发送了数据,内网服务器不是会给我返回下面的4个界面吗,而我又是直接输出的,怎么还不能打印出来呢

不错,内网服务器是会给你返回下面的4个界面
但这些页面不都是内网的吗?从外网怎么能直接访问到?
要是能从外网直接访问,那你还要写函数干什么?

我的意思是我本机在内网用curl函数取得这四个界面,然后将这四个界面的数据传给外网的访问者。为什么这4个界面不能打印出来呢,而且四个界面都取到了并且都传给了他怎么还说缺少界面呢?

比如布局页中有 
你说那个 top.htm 是指向哪里的?
如果是指向内网的,那么外网可以访问到吗?

iframe的机制是
1、浏览器获取携带iframe元素的页面
2、浏览器渲染页面
3、浏览器检测iframe元素
4、浏览器重新请求iframe包含的页面内容
5、渲染iframe包含的页面

对应你这里就是
1、浏览器发起请求login!checkLogin.action
2、渲染页面
3、检测到iframe元素(例如包含header.html的iframe)
4、浏览器重新请求header.html
5、渲染header.html页面

现在你的请情况是这样
1、浏览器对你的主机请求,你的主机请求内网login!checkLogin.action
2、浏览器渲染页面
3、检测到iframe元素
4、 浏览器对你请求header.html,你那里来的header.html?

那么处理方案就是
1、浏览器对你的主机请求,你的主机请求内网login!checkLogin.action,同时修改iframe中src由原来的header.html 改为 代理.php?page=headerl.html
2、浏览渲染页面
3、检测到iframe
4、对你的主机发起请求 代理.php?page=header.html, 代理.php去内网获取html内容返回
5、渲染header.html页面的实际内容

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Hot Topics

Java Tutorial
1663
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Explain different error types in PHP (Notice, Warning, Fatal Error, Parse Error). Apr 08, 2025 am 12:03 AM

There are four main error types in PHP: 1.Notice: the slightest, will not interrupt the program, such as accessing undefined variables; 2. Warning: serious than Notice, will not terminate the program, such as containing no files; 3. FatalError: the most serious, will terminate the program, such as calling no function; 4. ParseError: syntax error, will prevent the program from being executed, such as forgetting to add the end tag.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? What are HTTP request methods (GET, POST, PUT, DELETE, etc.) and when should each be used? Apr 09, 2025 am 12:09 AM

HTTP request methods include GET, POST, PUT and DELETE, which are used to obtain, submit, update and delete resources respectively. 1. The GET method is used to obtain resources and is suitable for read operations. 2. The POST method is used to submit data and is often used to create new resources. 3. The PUT method is used to update resources and is suitable for complete updates. 4. The DELETE method is used to delete resources and is suitable for deletion operations.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

Explain the difference between self::, parent::, and static:: in PHP OOP. Explain the difference between self::, parent::, and static:: in PHP OOP. Apr 09, 2025 am 12:04 AM

In PHPOOP, self:: refers to the current class, parent:: refers to the parent class, static:: is used for late static binding. 1.self:: is used for static method and constant calls, but does not support late static binding. 2.parent:: is used for subclasses to call parent class methods, and private methods cannot be accessed. 3.static:: supports late static binding, suitable for inheritance and polymorphism, but may affect the readability of the code.

How does PHP handle file uploads securely? How does PHP handle file uploads securely? Apr 10, 2025 am 09:37 AM

PHP handles file uploads through the $\_FILES variable. The methods to ensure security include: 1. Check upload errors, 2. Verify file type and size, 3. Prevent file overwriting, 4. Move files to a permanent storage location.

See all articles