0

I am trying to create a directory with mkdir code. When I use this code :

mkdir("test");

then, the "test" directory will be created. But when I try something like this

mkdir($_SESSION['username']);

then, I got an error saying

Warning: mkdir(): open_basedir restriction in effect. File() is not within the allowed path(s)

What does this mean? I also tried

$path = $_SESSION['username'];
mkdir($path);

and

mkdir("".$_SESSION['username']."");

but it gives me the same error message. What am I supposed to do?

Steven Tomko
  • 98
  • 11
  • 2
    Have you thought to reflect upon what the error actually means? – Zizouz212 Apr 09 '15 at 18:22
  • 2
    What is the output of: `var_dump($_SESSION['username']);` ? – Rizier123 Apr 09 '15 at 18:22
  • Have you tried outputting the value of `$path` to check for slashes or dots? – Randy Hunt Apr 09 '15 at 18:23
  • @Rizier123 - String(8) username.. I'm logged in without problems... – Steven Tomko Apr 09 '15 at 18:23
  • 3
    @StevenTomko What is the **exact** output? – Rizier123 Apr 09 '15 at 18:25
  • @Rizier123 - string(8) "Fregbind" – Steven Tomko Apr 09 '15 at 18:28
  • Are you saying that you login and it creates your directory without a problem, but if someone else tries, it throws an error? Have you checked to see what username they are trying to use - such as the username "/etc/sysconfig". – kainaw Apr 09 '15 at 18:28
  • That's why they have manuals http://php.net/manual/en/function.mkdir.php --- http://php.net/manual/en/function.error-reporting.php – Funk Forty Niner Apr 09 '15 at 18:29
  • @kainaw - no i'm not... It does not create even mine directory (Fregbind)... – Steven Tomko Apr 09 '15 at 18:29
  • @Fred-ii- - I did read this a while ago before I posted this – Steven Tomko Apr 09 '15 at 18:30
  • You're creating a folder, or trying to create one with no permissions set for it. Plus, did you start the session? Are you checking for errors? – Funk Forty Niner Apr 09 '15 at 18:31
  • @Fred -ii- - Lol you asked if I started session? Please, read all the comments. Var dump is my name... of course I did start session ffs And I did error reporting but nothing came on – Steven Tomko Apr 09 '15 at 18:33
  • The `f`'s am sure those stand for "fabulous friend", right? ;-) knew it. Ok, well take it up with the answer given below; they seem to be sure of their shot. We've said enough in comments now. – Funk Forty Niner Apr 09 '15 at 18:33
  • uhm.. Okay, it's working and I have no idea why... I swear that i did not change anything since I posted. I only used var_dump and uhm... My question is .. why is it working now without that error?...-____- the code is same as it was before I posted this o_q – Steven Tomko Apr 09 '15 at 18:38
  • 2
    @StevenTomko [**We now what you mean!**](http://s2.quickmeme.com/img/ca/cab0642c5c16b270935e65076d152a8d2e1d12dcf2520ee629b47a03dc86677c.jpg) – Rizier123 Apr 09 '15 at 18:39
  • http://stackoverflow.com/q/1846882/ similar issue. Same link in the answer below, is contained in that Q&A. I'm going to go walk my dog now. – Funk Forty Niner Apr 09 '15 at 18:42

1 Answers1

2

Make sure you prefix the folder name with the full path to where you want to create the folders. Ie, if you are trying to create folders under /tmp/users then you might use code like:

mkdir('/tmp/users/' . $_SESSION['username']);

You also need to make sure that you have configured PHP to allow you to access that path. See the open_basedir ini directive: http://php.net/manual/en/ini.core.php#ini.open-basedir

Jeremy Giberson
  • 1,063
  • 8
  • 15
  • File permissions might be an issue as well, you have to make sure the directory is writable by the web server. – Joseph Crawford Apr 09 '15 at 18:36
  • @JosephCrawford OP: *"And I did error reporting but nothing came on"* - Had it been a permissions issue, it would have told them so; least one would think it would. Who knows. – Funk Forty Niner Apr 09 '15 at 18:39