Page 1 of 1
Path Problems
Posted: Fri Jan 30, 2004 4:08 pm
by ut1205

I am new to PHP but not new to HTML and DOS. I have a PHP "login" script that works very well as long as the protected files are in the same folder as the script. Each protected page (about 2 dozen) include:
Code: Select all
<?php
include ("validate.php");
?>
As I like to keep things neat I need to place the 2 dozen files in about 4 different flolders. When I do that I, of course, get an error message that it can't find "validate.php". I've tried every combo of paths I know and nothing seems to work. What am I doing wrong?
Assume:
Main Folder is "Secure Website"
Sub Folder "Login" (contains "validate.php)
Sub Folder "Personal Info (contains files with the include statement)
Sub Folder "Stock Info (containg files with the include statement)
I need to point the "include" statement in "Personal Info" and "Stock Info" back to Login/validate.php.
Help would be appreciated.
Thanks
Jim
Posted: Fri Jan 30, 2004 4:32 pm
by Illusionist
try using ../ infront of Login/validate.php
if Stock Info is a sub Folder in Personal Info then you will need two ../../
Posted: Fri Jan 30, 2004 7:16 pm
by ut1205
Thanks for the reply.
I got the path right but it takes me back to the login page I get when both "user name" and "password" values are "null". When I try to login on that page it tells me it can't find "login.php" in that folder (stocks, etc.) I believe you have to stay in the "Login PHP Root Folder" to make it work. If you have any further ideas let me know. I hate to have that many unrelated files together in the same folder.
Thanks
Jim
Correction to my last post
Posted: Fri Jan 30, 2004 7:17 pm
by ut1205
"login.php" should be "validate.php"
Posted: Fri Jan 30, 2004 11:34 pm
by McGruff
You might try putting validate.php in your includes folder. phpinfo() will tell you where that is - or look in php.ini.
Some debug code using getcwd() might also help you figure out where you are, and therefore where you have to link back to.
Posted: Sat Jan 31, 2004 12:01 am
by markl999
I usually have a directory structure something like..
/www/foosite/main
/www/foosite/includes
then set the include_path in a vhost directive (in httpd.conf) something like,
<VirtualHost *>
ServerName foosite
DocumentRoot /www/foosite/main
php_value include_path /www/foosite/includes
php_value auto_prepend_file prepend.php
</VirtualHost>
Then put any common code (requires, defines etc..) in prepend.php
Then you can put all your 'protected files' in the includes directory and just use require_once 'validate.php'; in any file in the main directory (or sub directory of main) and it will find the file to require with no problems.