Path Problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

Path Problems

Post 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
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

try using ../ infront of Login/validate.php

if Stock Info is a sub Folder in Personal Info then you will need two ../../
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

Post 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
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

Correction to my last post

Post by ut1205 »

"login.php" should be "validate.php"
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
Post Reply