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.