richiejones24 Posted November 24, 2011 Share Posted November 24, 2011 Is there a better way to define the page name other than require("./anyfolder/any.php"); trouble is i define the page by using ./myfole/anyfile.php but if the page is called from deeper inside my site it dose not work. i have to change all the includes and put an additional . so it ends up looking like this ../myfole/anyfile.php Quote Link to comment https://forums.phpfreaks.com/topic/251756-require/ Share on other sites More sharing options...
Spring Posted November 25, 2011 Share Posted November 25, 2011 Set a root path var. For example: $root_path = http://www.google.com/ require($root_path . 'anyfolder/any.php') Quote Link to comment https://forums.phpfreaks.com/topic/251756-require/#findComment-1291030 Share on other sites More sharing options...
Pikachu2000 Posted November 25, 2011 Share Posted November 25, 2011 Except don't use a url to require a file, use a filesystem path. Quote Link to comment https://forums.phpfreaks.com/topic/251756-require/#findComment-1291036 Share on other sites More sharing options...
PFMaBiSmAd Posted November 25, 2011 Share Posted November 25, 2011 $_SERVER['DOCUMENT_ROOT'] will give you the absolute file system path to your document root folder (kind of why they named it what they did.) You can then append (concatenate) your path/filename.ext on to that to produce an absolute file system path that will work regardless of which file actually includes your file. If that doesn't accomplish what you want, you can use the include_path setting to get php to search for your include files in specific folders. Quote Link to comment https://forums.phpfreaks.com/topic/251756-require/#findComment-1291043 Share on other sites More sharing options...
ManiacDan Posted November 25, 2011 Share Posted November 25, 2011 Agreed, always use the DOCUMENT_ROOT. Quote Link to comment https://forums.phpfreaks.com/topic/251756-require/#findComment-1291051 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.