2011-09-08 115 views
0

很好地工作,我想從這種的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

回答

0

看看你的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

3

嗯,首先,這

$q = $_GET('q'); 

應該

$q = $_GET['q']; 

請注意
您正在使用的這種方法是高度不安全。考慮一個惡意的人提出以下請求。

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

通過提供Q的不同值時,攻擊者可以潛在地讀取由web服務器的用戶可讀的任何文件。

1

試試這個:

<?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> 
相關問題