我在PHP文件中有这段代码
$file = file_get_contents($url);
在PHP V5.2.17上运行
错误信息是:
failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
知道可能出现什么问题吗?
完整代码:
<?php
Header('Content-Type: application/javascript');
/*
* in JavaScript call with `encodeURIComponent`
* $.get('proxy.php?proxy_url='+encodeURIComponent('http://google.com?param=1¶m2=2'))
*/
error_reporting(~0);
ini_set('display_errors', 1);
$url = rawurldecode($_GET['proxy_url']);
$cb = ! empty($_GET['callback']) ? $_GET['callback'] : null;
if(preg_match('#xxx\.xxx\.com/xxx/#', $url)){
$url = preg_replace('#http\://xxx\.xxx\.com/xxx/#', '', $url);
}
if(! preg_match('#^https?:#', $url)){
$url = preg_replace('#^[\.\/]+#', '', $url);
if(!file_exists($url)){
echo 'File not found';
die(0);
}
}
if(preg_match('#\.xml$#', $url)){
header('Content-type: text/xml');
}
$file = file_get_contents($url);
if($cb){
header('Content-type: application/javascript');
echo $cb.'('.$file.');';
}else{
echo $file;
}