尝试使用CURLOPT_FOLLOWLOCATION
前任:
<?php
//I've added this two lines for debug, run the script and check for errors, when done, comment the lines.
error_reporting(E_ALL);
ini_set('display_errors', 1)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://SERVERIP/test/test.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
?>
根据您的评论,我更新了答案:
关闭 Linux 服务器上的 PHP 安全模式
Using SSH, connect to your server.
Once you are logged in, type su - root.
For your password, type the same password you used to connect to your server.
At the command prompt type:
vi /etc/php.ini
Go to the line safe_mode = on and press the "i" key.
Change the line to safe_mode = off and press the "Esc" key.
Type :wq! to save your file.
关闭 Windows 服务器上的 PHP 安全模式
Using Remote Desktop Connection, log in to your server as an administrator.
Open c:\windowsphp.ini in Notepad.
Change the line safe_mode = on to safe_mode = off.
Save and close php.ini.
在 php.ini 上启用 curl:
视窗:
找到 php.ini 并取消注释:
extension=php_curl.dll
Linux:
在带有 apache2 的 debian 上:
apt-get install php5-curl
/etc/init.d/apache2 restart
(如果是 php4,则为 php4-curl)
确保你的 php 是用 curl 支持编译的,使用以下代码制作一个脚本:
<?php
echo phpinfo();
?>
在那里搜索 CURL。