MDanz Posted September 23, 2009 Share Posted September 23, 2009 i'm doing a simple web crawler and i get this error message.. Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/ustackc1/public_html/crawler.php on line 2 Warning: file_get_contents(http://www.realgm.com) [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/ustackc1/public_html/crawler.php on line 2 Title: Head: whats wrong with the code? <?php $str = file_get_contents('http://www.realgm.com'); preg_match("/<title>(.*)<\/title>/", $str, $title); preg_match("/<head>(.*)<\/head>/", $str, $head); echo "Title: ".htmlentities($title[1])."<br />"; echo "Head: ".htmlentities($head[1]); ?> Link to comment https://forums.phpfreaks.com/topic/175217-error-message/ Share on other sites More sharing options...
Mark Baker Posted September 23, 2009 Share Posted September 23, 2009 A URL can only be used as a filename with this function if the fopen wrappers have been enabled. This setting (allow_url_fopen) can only be set in php.ini. Link to comment https://forums.phpfreaks.com/topic/175217-error-message/#findComment-923495 Share on other sites More sharing options...
MDanz Posted September 23, 2009 Author Share Posted September 23, 2009 so i have to save it as crawler.php.ini ? i'm confused how do i run it? Link to comment https://forums.phpfreaks.com/topic/175217-error-message/#findComment-923500 Share on other sites More sharing options...
Bricktop Posted September 23, 2009 Share Posted September 23, 2009 Hi MDanz, php.ini is what controls the environment variables for your PHP installation. Do you have access to your php.ini file? If so, edit it as directed above. Otherwise consider using cURL or fsockopen. Link to comment https://forums.phpfreaks.com/topic/175217-error-message/#findComment-923502 Share on other sites More sharing options...
TGWSE_GY Posted September 23, 2009 Share Posted September 23, 2009 MDanz php.ini is the config file that dictates what intrinsic functions are turned on or off. It works in the similar way of a .ini file in windows for a lot of applications, where you set properties for the application to run with. The same thing with php if you set url_fopen=1 in your php.ini(where your php compiler is installed on the server) it will turn it on. However I personally do not recomend using url_fopen because of security risks. I would suggest using cURL http://us3.php.net/manual/en/curl.examples-basic.php Link to comment https://forums.phpfreaks.com/topic/175217-error-message/#findComment-923514 Share on other sites More sharing options...
MDanz Posted September 23, 2009 Author Share Posted September 23, 2009 thx for all the help, how would i change this code just to get header and title of the webpage i've entered? <?php // create curl resource $ch = curl_init(); // set url curl_setopt($ch, CURLOPT_URL, "www.realgm.com"); //return the transfer as a string curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // $output contains the output string $output = curl_exec($ch); // close curl resource to free up system resources curl_close($ch); ?> Link to comment https://forums.phpfreaks.com/topic/175217-error-message/#findComment-923523 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.