Dan_Mason Posted April 7, 2009 Share Posted April 7, 2009 Hello again! Back with another annoying problem! ??? I am trying to re-arrange my Root Directory in my Web-server so that I can access files easily and know where they are. Here is the Layout of my Directory: Report-->AppLib -->CSS -->Documents -->Images -->Graph -->Javascript -->Main Etc etc, You get the idea. There are appropriate files in each folder so that they are easily accessed. The problem i am having is linking the files together. I need the path for include's to be variable, as when I take this on-site (It is a local network based Report System), it will be placed under a different directory to the one i am testing it in now. Eg Instead of <?php Include 'C:\\Program Files\\Apache\\htdocs\\Report\\AppLib\\'; ?> I need <?php Include $FilePath . 'Applib\\'; ?> I have tried using These functions so far: <?php //Function to Return Server name function get_server() { $protocol = 'http'; if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') { $protocol = 'https'; } $host = $_SERVER['HTTP_HOST']; $baseUrl = $protocol . '://' . $host; if (substr($baseUrl, -1)=='/') { $baseUrl = substr($baseUrl, 0, strlen($baseUrl)-1); } return $baseUrl . '/'; } ?> That is for linking HTML files to eachother, as instead of a file path, a URL is required instead <?php //Start Session session_start(); define('INCLUDE_PATH',dirname(__FILE__)); $_SESSION['INCLUDE_PATH'] = INCLUDE_PATH; ?> The above piece of code is used for 'Include' and 'Require' filepath's but Niether of the 2 above codes seem to work! all i get on screen is ans HTTP 500 Server Error, and I cant fins whats wrong by De-bugging the code in Eclipse! One other question, Does anyone know of a better programming Environment than Eclipse, because i seem to be encountering alot of problems with it! Thanks in advance for any help Link to comment https://forums.phpfreaks.com/topic/152948-http_host-problem/ Share on other sites More sharing options...
Axeia Posted April 7, 2009 Share Posted April 7, 2009 I use the following codesnippet in the CMS I'm building: <?php define( '_CMS_PATH_ROOT_', dirname( dirname( __FILE__ ) ), true ); function cmsAutoLoad( $pClassName ) { if( strpos( $pClassName, 'cCms' ) === 0 ) { require_once _CMS_PATH_ROOT_ . '/libs/cms/'.$pClassName.'.class.php'; } } //Register cmsAutoLoad as an autoloader, in order to prevent clashes with other autoloaders (as opposed to the magic method __autoload) spl_autoload_register("cmsAutoLoad"); ?> And include the file this is in, in every file related to the CMS. PS: spl_autoload_register is only in php quite recently, if you got an older version than supported simply remove the last line and rename cmsAutoLoad to __autoload ----- So that's quite similar to your code and it should work, do you have error reporting enabled? (Don't think this is the type of error where the IDE is to blame). Link to comment https://forums.phpfreaks.com/topic/152948-http_host-problem/#findComment-803271 Share on other sites More sharing options...
Dan_Mason Posted April 7, 2009 Author Share Posted April 7, 2009 Cheers man, but still having a problem. i am getting just the number 1 outputted to the screen. I think i have changed all of the appropriate parts to fit my system :S <?php define( '_CMS_PATH_ROOT_', dirname( dirname( __FILE__ ) ), true ); function cmsAutoLoad( $pClassName ) { if( strpos( $pClassName, 'cCms' ) === 0 ) { require_once _CMS_PATH_ROOT_ . '/AppLib/'.$pClassName.'MPDSData.php'; } } //Register cmsAutoLoad as an autoloader, in order to prevent clashes with other autoloaders (as opposed to the magic method __autoload) echo spl_autoload_register("cmsAutoLoad"); ?> Is there anything still in there that is specific to you system?? Link to comment https://forums.phpfreaks.com/topic/152948-http_host-problem/#findComment-803278 Share on other sites More sharing options...
Axeia Posted April 7, 2009 Share Posted April 7, 2009 The require once include is prefixed with the wrong global variable, look at my post again, editted it since as I don't really want google associating my name to the CMS name (yet). I'd appreciate it if you'd change your quote as well. [edit] Looking at your own code, I suspect mine has one dirname too many and you might want to get rid of the if statements around it. And are you sure you're looking for /AppLib/'.$pClassName.'MPDSData.php'? don't think the classname variable there makes much much sense, try an echo of the same path to see what it's trying to do. Link to comment https://forums.phpfreaks.com/topic/152948-http_host-problem/#findComment-803282 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.