2016-11-22 156 views
0

當php_self以html形式加載時,我的腳本加載了url的標題。警告:implode():在加載頁面傳遞的參數無效

<?php 
$bk_url=$_REQUEST['bk_url']; 
$remote_url = $bk_url; 
$from_remote_url = implode("", file("".$remote_url)); 
if(preg_match("/<title>(.+)<\/title>/", $from_remote_url, $regs)) { 
} else { 
echo "<br> Title empty. Manual insert"; 
} 
?> 

當負載PHP頁面,會顯示兩個錯誤:

Warning: file(http://): failed to open stream: operation failed

與此錯誤:

Warning: implode(): Invalid arguments passed

我有試着去發現計算器一個解決方案,但沒有找到任何解決方案。

如何解決這兩個錯誤? 謝謝

+0

if(!strlen($ _ REQUEST ['bk_url']))exit(「Can not run with empty URL」); –

+0

它沒有什麼可怕的爆炸'$ from_remote_url = implode(「」,file(「」。$ remote_url));' – RiggsFolly

+0

它總是一個好主意來檢查一個$ _POST或$ _GET參數是否已經真正被傳遞,並且它實際上在嘗試使用'isset()'或'empty()'' – RiggsFolly

回答

0

您只需在用戶提交表單時運行代碼。所以先檢查是否設置了變量。

if (isset($_REQUEST['bk_url'])) { 
    $bk_url=$_REQUEST['bk_url']; 
    $remote_url = $bk_url; 
    $from_remote_url = implode("", file("".$remote_url)); 
    if(preg_match("/<title>(.+)<\/title>/", $from_remote_url, $regs)) { 
    } else { 
     echo "<br> Title empty. Manual insert"; 
    } 
} 
相關問題