View Full Version : get around safe mode?

06-11-2006, 04:42 PM
I run a website on a server in PHP safe mode.
I want to read an url on another server through php to store the content of the url in a mysql database.

if I use things like file() or readfile() I get errors like these:

Warning: fopen() [function.fopen]: URL file-access is disabled in the server configuration in ...

I found a httpclient class that can get around this, but it is a little too complicated for me. It gives output to the screen, but I don't find how to store it in a variable.

Are there any other ways or easy examples how to read an url through http?
or is there another possibility to get around this issue?

thanks in advance


06-11-2006, 07:04 PM
use file_get_contents() : http://us3.php.net/manual/en/function.file-get-contents.php

06-11-2006, 09:02 PM
If allow_url_fopen is disabled then file_get_contents() will also not work. fsockopen() is the best way to go. There are some pre-made scripts to do this for you if you have a quick search.

06-18-2006, 12:27 PM
file_get_contents() doesn't seem to work either:

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /home/infogroep/www/igweb/geturl.php on line 18

Warning: file_get_contents(http://www.dnsstuff.com/tools/city.ch?ip= [function.file-get-contents]: failed to open stream: no suitable wrapper could be found in /home/infogroep/www/igweb/geturl.php on line 18

if I use the examplescript of fsockopen() from the php website, I get this as a result:

Warning: fsockopen() [function.fsockopen]: unable to connect to http://www.google.com (Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?) in /home/infogroep/www/igweb/geturl.php on line 2
Unable to find the socket transport "http" - did you forget to enable it when you configured PHP? (10922)

the script is:
$fp = fsockopen("http://www.dnsstuff.com/tools/city.ch?ip=", 80, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Connection: Close\r\n\r\n";

fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);

any ideas?

06-18-2006, 01:31 PM
I have two ways to try. For the first you need to be able to use .htaccess files. Also, if this method works it could really tick off your host so ask first. Put this in the .htaccess file in your main directory. If there is no .htaccess then create it

php_flag safe_mode off

You can also try using the PHP ini_set() (http://www.php.net/manual/en/function.ini-set.php) function

An example of its use would be this:

ini_set('safe_mode', 'off');

06-18-2006, 02:13 PM
I created a .htaccess file in my webroot. The script that is trying to read an url is in asubdirectory of the root.
I just made an empty file and copied the line you gave me. This didn't work.
I placed the line for setting the ini settings from the script, but that didn't work either. Should I ask the system administrator of the server to allow at least something that I want?

the thing I'm trying to do is to read a webpage (with some parameters given to it) on another server and to store the result in a mysql database. Maybe there is a way to do this with sql queries that I'm not aware of?

06-18-2006, 10:29 PM
Turning safe mode off is an open invitation for certain "people" to destroy not only your site but others hosted on the same server. Security options are turned on for a reason.

06-20-2006, 12:35 PM
I'm aware of that.

But I'd like to read some webpage and store the content in a database when a message is posted to my guestbook. Is there now way to get around this?

06-20-2006, 10:27 PM
Have you talked to your hosting provider about it. Usually there are three or four security options where they may consider turning one off for you provided that all of the others are turned on.