English 中文(简体)
非常奇怪的php包括行为...
原标题:Very strange php include behavior..

I am experiencing some very strange behavior when including a php file.
I need to load a script that is not on the same domain as the page that will be calling it.

I have already created a system that works using cURL, but I just recently found out that many of the sites that will need to have access to this script, do not have cURL installed. I did, however, notice that these sites have allow_url_fopen set to on. With this knowledge I got started creating a new system that would let me just include the script on the remote site.

Just testing this out, I coded the script test.php as follows:

<?php 
echo("test");
?>

我把这个脚本 包含在远程页面上 使用:

<?php
include("http://mydomain.com/script.php");
?>

and it works no problem and "test" is printed at the top of the page.

However, if I add a function to the script and try to call the function from the page, it crashes.
To make it worse, this site has php errors turned off and I have no way of turning it on.

To fully make sure that I didn t just mess up the code, I made my test.php look like this:

<?php
function myfunc()
{
return "abc";
}
?>

然后在包括文件的页面上:

<?php 
include("http://mydomain.com/script.php");
echo(myfunc());
?>

And it crashes. Any ideas would be greatly appreciated.

最佳回答

这不是奇怪的行为, 但是因为您在互联网上加载文件( 注意WorldwideWeb), 在文件被发送到您的包含功能之前, 就会被解释 。

由于对脚本进行了解释,没有函数是可见的,只有脚本的输出。

要么将其装入 FTP 上,要么为函数创建 API 。

问题回答

我猜测 : http://mydomain.com/ prime.php 的PHP 是由我的domain.com的网络服务器 < 强力 > 解释 。 您的重写 包括 包括 是该脚本的 结果 。 对于简单的 > echo ("test") 来说,此功能“ test" 。 函数不会产生任何输出, 也没有提供给 < code> 包括 < /code> 脚本 。 只需访问浏览器中的 < code> http:// mydomain.com/ scrip.php 就可以确认这一点, 并查看您得到什么。 您需要阻止我的domain.com 实际解释 PHPPP 文件, 并仅作为纯文本返回它 。

< 坚固> 但是: 这听起来像一个坏主意。 跨域包括一个反模式。 它不仅会让您遇到安全问题, 而且会让每页的负载不必要地慢。 如果跨域包含是答案, 您的问题是错误的 。

您正在包含来自 test.php 而不是服务器端源代码的客户端输出。 重新命名 test.php 来测试.php 来防止执行脚本。 但是, 从安全角度来说, 这很危险 。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...