繁体   English   中英

为了让 file_get_contents() 在客户端工作,服务器端脚本应该包含什么?

[英]What should a server-side script contain in order for file_get_contents() to work on the client side?

这是我第一次尝试在文件 (index.php) 中使用 file_get_contents():

echo $globalIP=file_get_contents("tools.php"); 

tools.php的内容暂且如下:

<?php
$ip=$_SERVER['REMOTE_ADDR'];
echo $ip;
?>

但是当我运行 index.php 时,它根本不显示任何内容。

特别是,Inte.net 上有关 file_get_contents() 的所有信息都与客户端呈现有关,与服务器端脚本应包含的内容无关。 我还在 tools.php 中尝试了 stream_context_create() ,但无济于事。

顺便说一句,这个想法是将 URL 替换为

$globalIP=file_get_contents("http://bot.whatismyipaddress.com");

用我自己的脚本。 Whatismyipaddress 返回一个包含 IP 的字符串,仅此而已,这正是我要查找的内容。

答案要简单得多:

如果使用相对链接,则显示实际文件的php代码: file_get_contents("tools.php") !!!!

为了让它工作,需要一个完整的 URL,在我的例子中:

file_get_contents("http://localhost/tools.php");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM