Rommeo Posted August 21, 2008 Share Posted August 21, 2008 Hi There is a small script which i have to add in every php files. I m using "include" for to do this. But my problem is about the link of the file. my document tree is like this : apage apageWhichpageInfoIncluded.php page pageinfo.php newcode code.php I wanna include code.php to pageinfo.php Let me explain clearly ; <?php include('/newcode/code.php'); ?> This does not work. I wanted it to reach that directory over the main directory ( like links ) But it's trying to find the code.php in /page/newcode/code.php which i dont want, so as a result of this. It does not work. <?php include('../newcode/code.php'); ?> This works, but when i include pageinfo from another page, this does not work anymore. <?php include('http://www.mysite.com/newcode/code.php'); ?> This also works but at this time, there are some problems about the sessions. how can i solve this problem ? I ll be glad if anyone can help. Thanx in advance. Link to comment https://forums.phpfreaks.com/topic/120693-solved-a-question-about-include/ Share on other sites More sharing options...
MasterACE14 Posted August 21, 2008 Share Posted August 21, 2008 try the full path: <?php include('user/public_html/newcode/code.php'); ?> Link to comment https://forums.phpfreaks.com/topic/120693-solved-a-question-about-include/#findComment-621906 Share on other sites More sharing options...
PFMaBiSmAd Posted August 21, 2008 Share Posted August 21, 2008 For code example 1, a leading slash in a file system path refers to the root of the current disk. For code example 2, relative file system paths (edit: starting with ./ or ../) are relative to the current working directory, which is that of the main script (unless you want to execute a statement to change the current working directory before the include and then changed it back after the include.) For code example 3, using a URL/HTTP request causes the included file to be parsed separately and you only receive any content that is output by that script. The solution is to form an absolute file system path using - include($_SERVER['DOCUMENT_ROOT'] . '/newcode/code.php'); Link to comment https://forums.phpfreaks.com/topic/120693-solved-a-question-about-include/#findComment-621913 Share on other sites More sharing options...
Rommeo Posted August 21, 2008 Author Share Posted August 21, 2008 PFMaBiSmAd thank you so much! Now it works. No problem .. (: Link to comment https://forums.phpfreaks.com/topic/120693-solved-a-question-about-include/#findComment-621921 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.