请教个fopensocket的问题
本地WAPM环境,php.ini有打开allow_url_fopen = On
write.php
$fp = fsockopen('localhost',80,&$errno,&$errstr,5);
if(!$fp)
{
echo "$errstr ($errno)
\n";
}
else
{
fputs($fp,"GET / HTTP/1.0\nHost: http://localhost/1.php");
fclose($fp);
}
?>
在localhost根目录下存在1.php,但测试运行write.php后,
发现1.php并没有被执行,单独执行1.php是可以运行
请问为什么?
试过把http://localhsot/1.php改为1.php也不行;过程中没提示无法创建套链接
回复讨论(解决方案)
$fp = fsockopen('localhost', 80, $errno, $errstr, 5); if(!$fp) { echo "$errstr ($errno)<br />\n"; }else { fputs($fp,"GET /1.php HTTP/1.0\r\nHost: localhost\r\nConnection: Close\r\n\r\n"); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp);}
$fp = fsockopen('localhost', 80, $errno, $errstr, 5); if(!$fp) { echo "$errstr ($errno)<br />\n"; }else { fputs($fp,"GET /1.php HTTP/1.0\r\nHost: localhost\r\nConnection: Close\r\n\r\n"); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp);}
在本地测试的时候,其他电脑访问我这台电脑,用ip的方式可以正常执行,即假设我测试ip为192.168.10.60,
其他电脑使用http://192.168.10.60/write.php可以正常;
但把程序放到服务器上去,服务器ip假设为192.168.10.3,
运行却无法执行,需要把
连接方式变成192.168.10.3,然后fputs的时候,要写绝对路径才可以……这是啥情况?
这不是很正常吗?
你放到192.168.10.3
就不是localhost了,当然要用绝对ip访问,有什么问题?
这不是很正常吗?
两点不正常
1、以我本机为测试主机时,其他机器访问我本机,在使用localhost的时候可以正常运行;而把程序放到服务器时,我本机访问服务器就不行;
2、我说的写绝对路径是不是指fsocketopen建立链接时写,而是譬如当程序是放在web目录下的ca/ma目录下时,下面的
fwrite的路径要写192.168.10.3/ca/ma/1.php,即便我write程序与1.php程序是放置在同一目录下也需要这样。
但同样的这个现象我放在本地时,用其他电脑访问本地却正常。本地是win系统,服务器是linux系统,然道是因为OS的关系?
1、程序是在你的机器上运行的,所以用 localhost 能访问到是正常的,用你机器的 ip 能访问到也是正常的
2、当程序搬迁至服务器上时,按理说用 localhost 也是能访问到的,但由于服务器的特殊性可能没有做 127.0.0.1 到 localhost 的映射,那么就访问不到了。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.
