1

I am getting the error

Warning: fopen() [function.fopen]: open_basedir restriction in effect. File(/) is not within the allowed path(s): (VIRTUAL_DOCUMENT_ROOT:/tmp/) in /www/elitno.net/s/p/anger2/home/site/classWebPage.php on line 83

My phpinfo file is here -> http://spaceranger2.elitno.net/phpinfo.php

The line where the error is occuring is here:

function openLink(){
    $this->fp = fopen($this->URL, "rb");
    array_shift($http_response_header);
    $this->headers = $http_response_header;
}

I only have access to .htaccess but not my php.ini file; i tried using this

open_basedir = "VIRTUAL_DOCUMENT_ROOT:/tmp/:/www/elitno.net/s/p/ranger2/home/site/"

but this generates 500 internal error's, any suggestions?

David Wilkinson
  • 5,060
  • 1
  • 18
  • 32
user1905494
  • 55
  • 1
  • 5

1 Answers1

0

Generally fopen is only allowed to open files to which the user running the script has access.

You have designed your function openLink() to actually open a particular URL. You should note that when using fopen it actually indicates opening a file on the disk. If you pass values like / or /filename.txt it is actually going to try and open the file on the disk at that absolute filesystem path.

From your question data you are telling fopen to open /. That's the root of the filesystem of the server. Your user definitely won't have access to it (and hence the error you see).

If you want to open a relative path to your website consider prefixing the site URL to the $this->URL variable before passing it to fopen to indicate that you are trying to open a URL.

You can do something on the following lines:

function openLink(){
    $siteURL = "http://www.example.com";
    $urlToOpen = $siteURL . $this->URL;
    $this->fp = fopen($urlToOpen, "rb");
    array_shift($http_response_header);
    $this->headers = $http_response_header;
}
Tanzeel Kazi
  • 3,797
  • 1
  • 17
  • 22