Page 1 of 1

ERROR when trying to use s PHP to script to searh GOOGLE

Posted: Fri Jan 02, 2004 5:00 pm
by senin
I'm getting the folling error in the following piece of code
Warning: file("http://www.google.com/search?q=test") - Success in search.php on line 8

Code: Select all

function search ($searchsite="test", $query="test")
{
        $encodedquery = urlencode($query);
        $site="http://www.google.com/search?q=test";
        $results = file("$site"); //this is line 8 btw

        foreach($results as $line)
        {
                echo $line;
        }
}

search();

?>
In the above code I'm only tring to verify that the website with the google results will be retrieved. None of the variable arguments are being used.

If I only put "http://www.google.com/" it works fine. I've tried retrieving multiple sites and they all work fine. I only get the error when pages are 404. I'm just lost as to why "http://wwww.google.com/search?q=test" gives this warning when I can browse to it easily.

Thanks in advance for any help.

Posted: Fri Jan 02, 2004 5:07 pm
by JAM
Your error levels are to low, or you would get noticed of the extra dot on line 7. Remove that and it should work. (Does here)

Posted: Fri Jan 02, 2004 5:19 pm
by senin
I'm sorry about the dot, I'll edit it out immediately. my script doesn't contain it.

I'm still unable to retrieve the website. would you mind posting what version of PHP you are using and anything else you think could be causing the difference in our results.

thanks again.

Posted: Fri Jan 02, 2004 5:22 pm
by JAM
Oh, how asuming of me. Here goes.

PHP Version: 4.3.4
Display Errors: On
Error Level: E_ALL
Register Globals: Off

Code: Select all

<?php
echo '<pre>';
echo 'PHP Version: '.phpversion()."\n";
echo 'Display Errors: '.(ini_get('display_errors') == '1' ? 'On' : 'Off')."\n";
echo 'Error Level: '.(ini_get('error_reporting') == '2047' ? 'E_ALL' : 'Not E_ALL')."\n";
echo 'Register Globals: '.(ini_get('register_globals') == '' ? 'Off' : 'On')."\n";
echo '</pre>';
?>
[Edit: Verified it yet again, and yes it works. --JAM]
[Edit II: http://phpdn.jam.nu/GoogleRetriever/ Verifying at my host also. -- JAM]

Posted: Fri Jan 02, 2004 7:27 pm
by senin
Thanks a lot Jam. I installed the latest PHP and Apache and now it works.