Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    May 2004
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy get around safe mode?

    Hello,
    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:
    Code:
    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

    Johan

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,839
    Thanks
    21
    Thanked 157 Times in 148 Posts
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #3
    Regular Coder
    Join Date
    Dec 2004
    Location
    Manchester, UK
    Posts
    134
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    New Coder
    Join Date
    May 2004
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    file_get_contents() doesn't seem to work either:
    Code:
    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=134.184.36.108) [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:
    Code:
    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:
    Code:
    <?php
    $fp = fsockopen("http://www.dnsstuff.com/tools/city.ch?ip=134.184.36.108", 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);
       }
       fclose($fp);
    }
    ?>
    any ideas?

  • #5
    New Coder
    Join Date
    Mar 2005
    Location
    Indiana (USA)
    Posts
    50
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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
    Code:
    php_flag safe_mode off
    You can also try using the PHP ini_set() function

    An example of its use would be this:
    PHP Code:
    ini_set('safe_mode''off'); 
    Last edited by chiefbutz; 06-18-2006 at 01:34 PM.

  • #6
    New Coder
    Join Date
    May 2004
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #7
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #8
    New Coder
    Join Date
    May 2004
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •