Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Funny 500 error when accessing page from php script

Links for php scripts

Moderators: macek, egami, gesf

Funny 500 error when accessing page from php script

Postby fbartolom » Sun Apr 01, 2012 11:57 pm

Hullo, I would like to parse page: http://gmmobile.atm-mi.it/wsbw/InfoTraffico/ that, as you may see, is regularly accessible.
Yet, when I try to access it through the php script at:http://www.miafoto.it/iPhone/inarrivo/phpMi/getLines.php in order to parse its content, I receive error:

Warning: file_get_contents(http://gmmobile.atm-mi.it/wsbw/InfoTraffico/) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in /iPhone/simplehtmldom_1_5/simple_html_dom.php on line 70


The contents of the php is the following:

Code: Select all
include('simple_html_dom.php');
// Create DOM from URL or file
$url='http://gmmobile.atm-mi.it/wsbw/InfoTraffico/';
echo $url;
$html = file_get_html($url);
echo $html;
$i=0;
foreach($html->find('option') as $content)
{
    $linea=$content->value;
    $destination=$content->title;
        $i++;

}


What might be the business and I could I fix the problem?

Thanks, Fabrizio Bartolomucci
fbartolom
New php-forum User
New php-forum User
 
Posts: 17
Joined: Sun Apr 01, 2012 11:52 pm

Re: Funny 500 error when accessing page from php script

Postby freshnet » Mon Apr 02, 2012 4:12 am

If you're looking to parse the contents of a page, you're better off using CURL. Here's an example

curl_setopt($ch, CURLOPT_URL,"http://www.google.com");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$content = curl_exec($ch);

This will put the entire contents of the google homepage into the $content variable.
User avatar
freshnet
php-forum Active User
php-forum Active User
 
Posts: 252
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada


Return to PHP Scripts

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.