pracasify Posted May 27, 2011 Share Posted May 27, 2011 Suppose, i have created a sub.domain.com and i want to include a file 'config.php' from root directory i.e domain.com . While i tried include("../config.php"); i wasn't successful. Anyone can help me please?? I need the solution very urgently, so please help me soon. pracasify@yahoo.com facebook.com/agptj Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/ Share on other sites More sharing options...
mikesta707 Posted May 27, 2011 Share Posted May 27, 2011 assuming that your subdomain's root folder is in the main root folder of your site, and config.php is also in the main root folder of your site, using ("../config.php") should work. What is your file structure like? What page is the include statement written in? Where is said page located? Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221266 Share on other sites More sharing options...
pracasify Posted May 27, 2011 Author Share Posted May 27, 2011 Friend, when i click on public_html folder the files are listed like this : public_html - config.php - sub (folder) - index.php here, index.php contains; <?php include("../config.php"); ?> Now, when i enter url, sub.domain.com ... i can see the error message that php cannot find the steam file or directory! Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221272 Share on other sites More sharing options...
mikesta707 Posted May 27, 2011 Share Posted May 27, 2011 Hmm, strange. Theoretically using '../config.php' should work. Have you tried using absolute using an absolute URL rather and a relative one? Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221276 Share on other sites More sharing options...
pracasify Posted May 27, 2011 Author Share Posted May 27, 2011 yup, i tried friend.. but that wasn't working.!! Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221279 Share on other sites More sharing options...
mikesta707 Posted May 27, 2011 Share Posted May 27, 2011 hmm, can you post the code you used with absolute pathing? Maybe you did something wrong with the absolute pathing. Does index.php only contain that 1 include statement, or is their more? Beyond some simple error, I really can't see why it wouldn't be able to find config.php. Perhaps you should open a ticket with your hosting provider Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221282 Share on other sites More sharing options...
pracasify Posted May 27, 2011 Author Share Posted May 27, 2011 the code goes on index.php like this : <?php include("../config.php"); ?> only this much friend, nothing else !! Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221293 Share on other sites More sharing options...
mikesta707 Posted May 27, 2011 Share Posted May 27, 2011 Well if you've tried both absolute and relative URL's without success, I can't be of much help. Perhaps you should try opening a ticket with your hosting provider Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221297 Share on other sites More sharing options...
pracasify Posted May 27, 2011 Author Share Posted May 27, 2011 okay friend, anyways, thanks for your interest towards my problem. Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221299 Share on other sites More sharing options...
.josh Posted May 27, 2011 Share Posted May 27, 2011 Friend, when i click on public_html folder the files are listed like this : public_html - config.php - sub (folder) - index.php So are you saying you can go to www.domain.com/config.php and that works? Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221302 Share on other sites More sharing options...
pracasify Posted May 27, 2011 Author Share Posted May 27, 2011 ya sure.. when i enter domain.com/config.php ~ it works domain.com/sub/ ~ it works (the file is included) but, when i enter sub.domain.com ~ it doesn't works... file is not included Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221304 Share on other sites More sharing options...
.josh Posted May 27, 2011 Share Posted May 27, 2011 what did you do to setup sub.domain.com? What is your virtualhost info? Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221306 Share on other sites More sharing options...
pracasify Posted May 27, 2011 Author Share Posted May 27, 2011 i logged in to cpanel, then clicked on subdomain and then gave new subdomain name.... to get my subdomain!! i am so surprised that same code is running on my next website!! i think that is problem of hosting or something else...!!! when i tried that on my another website, the code was running successfully!! Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221309 Share on other sites More sharing options...
.josh Posted May 27, 2011 Share Posted May 27, 2011 i logged in to cpanel, then clicked on subdomain and then gave new subdomain name.... to get my subdomain!! i am so surprised that same code is running on my next website!! i think that is problem of hosting or something else...!!! when i tried that on my another website, the code was running successfully!! can you please step back for a moment, clear your mind, pretend that you are someone else who doesn't know you or your situation, read what you just wrote, and try to determine if you could possibly solve this problem with the information you just gave? "I clicked buttons and it gave me a subdomain name" tells me...what? Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221312 Share on other sites More sharing options...
MadTechie Posted May 27, 2011 Share Posted May 27, 2011 Sounds like you messed up the sub domain creation to me Simple example file: /public_html/main_domain.php <?php $data = "I am HERE"; URL: http://www.madtechiesupport.com/Test_domain.php file: /public_html/Test_domain.php <?php include "main_domain.php"; echo $data; URL: http://subdomain.madtechiesupport.com/Test_domain2.php file: /public_html/subdomain/Test_domain2.php <?php include "../main_domain.php"; echo $data; Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221392 Share on other sites More sharing options...
PFMaBiSmAd Posted May 27, 2011 Share Posted May 27, 2011 It might be interesting to see what getcwd shows? Quote Link to comment https://forums.phpfreaks.com/topic/237660-including-a-file-of-root-directory-from-subdomain/#findComment-1221411 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.