Bman900 Posted June 26, 2009 Share Posted June 26, 2009 Well as we all know that if your inlcude file is in a directory above what you are in, you can not call a file with inlcude correctly. I need a way to fix this on shared hosting because not many people have dedicated hosting. Quote Link to comment https://forums.phpfreaks.com/topic/163760-how-to-fix-include-problem-in-php5/ Share on other sites More sharing options...
JonnoTheDev Posted June 26, 2009 Share Posted June 26, 2009 Well as we all know that if your inlcude file is in a directory above what you are in, you can not call a file with inlcude correctly. What do you mean, 'cannot call it wil include correctly'. You can include any file no matter what directory it is in // /docs/includes/config.php $id = 123; // /docs/files/index.php include($_SERVER['DOCUMENT_ROOT'].'docs/includes/config.php'); Quote Link to comment https://forums.phpfreaks.com/topic/163760-how-to-fix-include-problem-in-php5/#findComment-864076 Share on other sites More sharing options...
Bman900 Posted June 26, 2009 Author Share Posted June 26, 2009 Seee thats what I wanted. They way I did it in php4 was include ("../inlcude/config.php"); I noticed that your root folder is docs, stupidmquestion coming, Is that the same on all hosting? Take that stupid question away, I looked at it a bit more and see what you did. Quote Link to comment https://forums.phpfreaks.com/topic/163760-how-to-fix-include-problem-in-php5/#findComment-864082 Share on other sites More sharing options...
Tonic-_- Posted June 26, 2009 Share Posted June 26, 2009 Seee thats what I wanted. They way I did it in php4 was include ("../inlcude/config.php"); I noticed that your root folder is docs, stupidmquestion coming, Is that the same on all hosting? Take that stupid question away, I looked at it a bit more and see what you did. Well like he said you can include any file so long as its on the server its self and you know the directories. Most shared hosts put their system users in /home and your username is usually your directory (it is your directory if they use cPanel) If you don't know the full path to your account you can google around for a little php file that tells you the full directory path its in.. After you know what it is you just do it like include("/home/bruno/public_html/mytest/borat.php"); *Bruno being your username/directory* Quote Link to comment https://forums.phpfreaks.com/topic/163760-how-to-fix-include-problem-in-php5/#findComment-864084 Share on other sites More sharing options...
soycharliente Posted June 26, 2009 Share Posted June 26, 2009 If you don't know the full path to your account you can google around for a little php file that tells you the full directory path its in.. Or you could just echo the $_SERVER['DOCUMENT_ROOT'] variable yourself. Quote Link to comment https://forums.phpfreaks.com/topic/163760-how-to-fix-include-problem-in-php5/#findComment-864086 Share on other sites More sharing options...
Tonic-_- Posted June 26, 2009 Share Posted June 26, 2009 That works too. Quote Link to comment https://forums.phpfreaks.com/topic/163760-how-to-fix-include-problem-in-php5/#findComment-864087 Share on other sites More sharing options...
Bman900 Posted June 26, 2009 Author Share Posted June 26, 2009 If you don't know the full path to your account you can google around for a little php file that tells you the full directory path its in.. Or you could just echo the $_SERVER['DOCUMENT_ROOT'] variable yourself. I like that better since it is not server specific and if I need to deploy my project somewhere else, it works. Plus I have a server on my PC for testing there as well. Quote Link to comment https://forums.phpfreaks.com/topic/163760-how-to-fix-include-problem-in-php5/#findComment-864088 Share on other sites More sharing options...
JonnoTheDev Posted June 26, 2009 Share Posted June 26, 2009 Or, set your include path in a config file // config.php set_include_path(get_include_path().PATH_SEPARATOR.$_SERVER['DOCUMENT_ROOT']); Then you can easily include from this directory no matter where you are include('classes/xyz.class.php'); include('functions/xyz.func.php'); What you did here was to use a relative path They way I did it in php4 was include ("../inlcude/config.php"); The afformentioned above uses absolute paths Quote Link to comment https://forums.phpfreaks.com/topic/163760-how-to-fix-include-problem-in-php5/#findComment-864093 Share on other sites More sharing options...
Bman900 Posted June 26, 2009 Author Share Posted June 26, 2009 Or, set your include path in a config file // config.php set_include_path(get_include_path().PATH_SEPARATOR.$_SERVER['DOCUMENT_ROOT']); Then you can easily include from this directory no matter where you are include('classes/xyz.class.php'); include('functions/xyz.func.php'); What you did here was to use a relative path They way I did it in php4 was include ("../inlcude/config.php"); The afformentioned above uses absolute paths Alright so if I set up whatr you just said can I do what I described in my first post because I don't really get include('functions/xyz.func.php'); so basicly I set up that config file u showed my and do ("../inlcude/config.php"); Would that work like that? Quote Link to comment https://forums.phpfreaks.com/topic/163760-how-to-fix-include-problem-in-php5/#findComment-864101 Share on other sites More sharing options...
JonnoTheDev Posted June 26, 2009 Share Posted June 26, 2009 No, again that is a relative path (relative from the directory you are in) basicly I set up that config file u showed my and do ("../inlcude/config.php"); If my webservers document root for my domin abc.com is /var/www/html/abc.com/docs/ (remember a / at the beginning inclidates the root directory of the server. i.e in windows c:\) If I do set_include_path(get_include_path().PATH_SEPARATOR.$_SERVER['DOCUMENT_ROOT']); The this will set the include path to: /var/www/html/abc.com/docs/ So if I have directories under docs/ called functions & classes even if I am within the classes directory I can still use include('functions/xyz.func.php'); This is because I have set the path where it should look from for includes so it will be looking for: /var/www/html/abc.com/docs/functions/xyz.func.php This is an absolute path. Don't use relative paths as if you move files/folders it makes it harder to fathom out. Look up the difference between relative & absolute paths. Quote Link to comment https://forums.phpfreaks.com/topic/163760-how-to-fix-include-problem-in-php5/#findComment-864111 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.