0
votes

My script load a title of url when this load by php_self in a html form.

<?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";
}
?>

When load the php page, are displayed two errors:

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

and this error:

Warning: implode(): Invalid arguments passed

I have try to find a solution on stackoverflow but not find any solution.

How to fix this two errors? Thanks

1
if (!strlen($_REQUEST['bk_url'])) exit("Can't run with empty URL"); - Kevin_Kinsey
Its difficult imploding on nothing $from_remote_url = implode("", file("".$remote_url)); - RiggsFolly
Its always a good idea to check that a $_POST or $_GET parameter has actually been passed and that it actually has something in it before attempting to us it isset() or empty() - RiggsFolly
@Kevin_Kinsey And if $_REQUEST['bk_url']) does not exist like on pages first load, thats another error message - RiggsFolly
@Kevin_Kinsey: I try with your solution and work fine. I modify my web procedure to go at the target but work fine :) Thanks - Frankie

1 Answers

0
votes

You need to run the code only when the user has submitted the form. So check first to see if the variable is set.

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";
    }
}