z-boss
z-boss

Reputation: 17608

PHP cannot find my php files if not under htdocs folder

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"

Upvotes: 0

Views: 7982

Answers (3)

too much php
too much php

Reputation: 91038

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'

Upvotes: 1

cletus
cletus

Reputation: 625227

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

Upvotes: 3

Mark Rushakoff
Mark Rushakoff

Reputation: 258348

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.

Upvotes: 0

Related Questions