PHP会因某些原因无法

问题描述:

很好地工作,我想从这种的URL得到一个iframe:http://mydomain.com/frame.php?q=http://someotherdomain.comPHP会因某些原因无法

出于某种原因,我得到一个服务器错误与此代码并不能找出原因。有没有人看到错误?

谢谢!

<?php 

$q = $_GET('q'); 

function getTitle($Url){ 
     $str = file_get_contents($Url); 
     if(strlen($str)>0){ 
       preg_match("/\<title\>(.*)\<\/title\>/",$str,$title); 
       return $title[1]; 
     } 
}; 

?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title><?php echo getTitle($q) ?></title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
</head> 

<body> 

<?php echo "<iframe src='".$q."' style='width:100%;height:100%;border:0;'></iframe>" ?> 

</body> 
</html> 
+0

有什么错误讯息? – Teekin

看看你的Apache日志错误 它通常是:

tail -f /var/log/apache2/error.log 
+0

好的,它说致命的错误:功能名称必须是/var/www/clients/client0/web10/web/envios/redirect.php在线3上的字符串 – user906379

+0

你可以请复制redirect.php,第3行对你的问题? – GerManson

嗯,首先,这

$q = $_GET('q'); 

应该

$q = $_GET['q']; 

请注意
您正在使用的这种方法是高度不安全。考虑一个恶意的人提出以下请求。

http://mydomain.com/frame.php?q=..%2F..%2F..%2F..%2Fetc%2Fapache2%2Fhttpd.conf 

通过提供Q的不同值时,攻击者可以潜在地读取由web服务器的用户可读的任何文件。

试试这个:

<?php 

$URL = parse_url($_SERVER['REQUEST_URI']; 

/* make sure the title is the first parameter and only param passed, otherwise include a ltrim to get rid of everything starting with & */ 
$q = rtrim('=', $URL['query']); 

?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title><?php=$q?></title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
</head> 

<body style="margin: 0;"> 

<?php='<iframe src="' . $whateverURL . '" style="width: 100%; height: 100%; border: 0px;" />'?> 

</body> 
</html>