views:

478

answers:

3

By someone's advice I've put all my PHP files in a separate folder (inc) on the same level as htdocs. Only index.php is left in htdocs. So, it's like this:

C:\myproject\htdocs
- index.php

C:\myproject\inc
- login.php
- util.php
- register.php
...

Now, when I go to localhost in my browser index.php is processed and shown correctly. But any links to other php files are not found. I tried to prepend links with "inc", but they're still not found. What should I do?

My php.ini file has this line (it's on Windows):
include_path = ".;C:\myproject\inc"

A: 

I believe you need to escape the backslashes in your php.ini -- so it should be C:\\myproject\\inc. But as others have pointed out, you won't be able to use a browser to access the PHP files in your include directory, because the web server will not allow access to a directory outside the htdocs tree.

Mark Rushakoff
I prefer using slashes, but double backslashes should be okay too (on Windows enviroment)
w35l3y
+2  A: 

The point of an include directory is to put files you don't want to be accessible by a Webserver. If login.php needs to be accessible via a URL like:

http://yourdomain.com/login.php

then don't put login.php in the include directory. Putting util.php in an include directory makes sense because you never want this:

http://yourdomain.com/util.php

cletus
+1  A: 

You can't put web-accessible files outside the htdocs folder, you should be using the 'inc' folder for files like 'database_functions.inc' which should not be opened directly in your browser:

http://localhost/index.php // directly accessible - goes in htdocs
http://localhost/login.php // directly accessible - goes in htdocs
http://localhost/register.php // directly accessible - goes in htdocs

http://localhost/util.php // you don't want people loading this file directly - put in 'inc'
http://localhost/database_functions.php // you don't want people loading this file directly - put in 'inc'
too much php