0

I'm using XAMPP on Windows 8.1.

I've this in apache config:

DocumentRoot "C:\Users\David\Dropbox\Programming\PHP"
<Directory "C:\Users\David\Dropbox\Programming\PHP">

VHosts:

<VirtualHost *:80>
ServerName http://spedice
DocumentRoot "C:\Users\David\Dropbox\Programming\PHP\Projects_Kuba\Spedice\SczCMS\www"
</VirtualHost>

<VirtualHost *:80>
ServerName http://domaciucetnictvi
DocumentRoot "C:\Users\David\Dropbox\Programming\PHP\Projects_Kuba\DomaciUcetnictvi\www"
</VirtualHost>

But if I try accessing root directory - C or accessing some folder like C:\Program Files etc. It normally works. How can I disable going outside of this folder: C:\Users\David\Dropbox\Programming\PHP?

Fxp:

script.php

<?php
mkdir('../../../../../../folder');
?>

Placed in: C:\Users\David\Dropbox\Programming\PHP\Projects_Kuba\DomaciUcetnictvi\www

Called like: http://domaciucetnictvi/script.php

Thanks!

2
  • If you are actually accessing C:\Users\David\Dropbox\Programming\PHP in your address bar - and I fear you do - Apache doesn't do anything - you are just using your browser as an explorer. What you should do (and which magically makes your PHP code actually work) is visit localhost
    – snout1979
    Jan 3, 2015 at 17:08
  • I've updated my question. Hope its understandable now :)
    – sczdavos
    Jan 3, 2015 at 21:00

1 Answer 1

4
+50

Try to modify the open_basedir settings in your PHP config (just see Runtime Configuration for further information). This will prevent PHP from accessing directories outside of the definded basedir(s).

---EDIT---

To be a bit more conclusive. You can set open_basedir in your Apache configuration file, php.ini, or in a .htaccess file.

In php.ini, you can do this for example by adding:

open_basedir = "/path/to/first/folder:/path/to/second/folder"

In .htacces you can do it with:

php_flag open_basedir "/path/to/first/folder"

In your Apache config try:

<Directory /docroot1>
   php_admin_value open_basedir /path/to/first/folder
</Directory>

<Directory /docroot2>
   php_admin_value open_basedir /path/to/second/folder
</Directory>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.