etdsbastar Posted September 3, 2011 Share Posted September 3, 2011 Hello there, I am developing a project in which there are different files in different folders: ROOT -> INDEX.PHP <?php require_once( 'includes/core.php' ); ?> INCLUDES -> CORE.PHP <?php // Where we are ? define( 'BASEPATH', $_SERVER['DOCUMENT_ROOT'] . '/csm/' ); // require config.php if ( file_exists(BASEPATH . 'config.php') ) require_once ( BASEPATH . 'config.php' ); else die ( 'Master configuration file not found, can\'t continue.' ); // Include common sessions file if ( file_exists( BASEPATH . 'includes/common.php' ) ) { require_once( BASEPATH . 'includes/common.php' ); } else { die ( 'Common include file not found. Possible location: ' . BASEPATH . 'includes/common.php' ); } // Require functions.php if ( file_exists(INCLUDEPATH . 'functions.php') ) require_once ( INCLUDEPATH . 'functions.php' ); else die ( 'Functions file not found, can\'t continue.' ); // Include common library file if ( file_exists( BASEPATH . 'lib/classes.php' ) ) { require_once( BASEPATH . 'lib/classes.php' ); } else { die ( 'Common library file not found. Possible location: ' . BASEPATH . 'lib/classes.php' ); } // Create a new instance of DB class. $_DB = new DB; if ( file_exists( BASEPATH . 'template/index.php' ) ) html_header_location ( 'template/index.php' ); else die ( raise_error('03') ); ?> None of the files included in the above CORE.PHP file ( config.php, common.php, functions.php, classes.php, and template/index.php ) detect the value of BASEPATH. Every file is filled with error: Notice: Use of undefined constant BASEPATH - assumed 'BASEPATH'... I am just confused performing the use of GLOBAL (global) variables/constants in either files. Anyone, please help. Quote Link to comment Share on other sites More sharing options...
micah1701 Posted September 3, 2011 Share Posted September 3, 2011 are you saying that the included files can't access the defined variable? or that the files aren't being included because the the code you listed above doesn't seem to load the defined variable currently? if its the latter, maybe the issue isn't that the variable doesn't exist but that the path it stores is not the actual base path to your files. is the folder that all those files are in really "csm" and not maybe something more common like "cms"? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 3, 2011 Share Posted September 3, 2011 There's nothing technically wrong what what you are doing (just tested.) Are you sure $_SERVER['DOCUMENT_ROOT'] is actually what you think it is (a file system path)? Perhaps someone either mis-configured your virtual host or intentionally set it so that it actually contains the URL to your domain root? Quote Link to comment Share on other sites More sharing options...
etdsbastar Posted September 3, 2011 Author Share Posted September 3, 2011 are you saying that the included files can't access the defined variable? or that the files aren't being included because the the code you listed above doesn't seem to load the defined variable currently? if its the latter, maybe the issue isn't that the variable doesn't exist but that the path it stores is not the actual base path to your files. is the folder that all those files are in really "csm" and not maybe something more common like "cms"? Yes, if I call the constant BASEPATH from any of the above stated files, its giving me warning messages. and what do you mean by LOAD THE DEFINED VARIABLE CURRENTLY. I have also checked the file, and the paths, all are configured correctly. Quote Link to comment Share on other sites More sharing options...
etdsbastar Posted September 3, 2011 Author Share Posted September 3, 2011 There's nothing technically wrong what what you are doing (just tested.) Are you sure $_SERVER['DOCUMENT_ROOT'] is actually what you think it is (a file system path)? Perhaps someone either mis-configured your virtual host or intentionally set it so that it actually contains the URL to your domain root? My localhost is working perfectly... How can I check that its configured properly??? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 3, 2011 Share Posted September 3, 2011 You can echo $_SERVER['DOCUMENT_ROOT'] to see what it is. Quote Link to comment Share on other sites More sharing options...
etdsbastar Posted September 3, 2011 Author Share Posted September 3, 2011 You can echo $_SERVER['DOCUMENT_ROOT'] to see what it is. Its showing the path in my site-available settings. Why the constant BASEPATH not being accessed by other files? Here is the sample of common.php in the includes directory: <?php // Common path definitions define( 'INCLUDEPATH', BASEPATH . 'includes/' ); define( 'DATAPATH', BASEPATH . 'data/' ); define( 'LIBPATH', BASEPATH . 'lib/' ); define( 'REPORTSPATH', BASEPATH . 'reports/' ); define( 'TEMPLATESPATH', BASEPATH . 'template/' ); $_LF = "\n"; $_TAB = " "; $_CHARSET = CHARSET; // declare some session variables after starting a pure session $_SESSION['curdate'] = Date('d-m-Y'); // define URL path $_BASE_HREF = 'http://' . DBHOST . '/csm/'; ?> Here is the error/warning: Notice: Use of undefined constant BASEPATH - assumed 'BASEPATH' in .../csm/includes/common.php on line 13 Even I had removed the BASEPATH definition from common.php file and shifted to Index.php on root folder: <?php define( 'BASEPATH', $_SERVER['DOCUMENT_ROOT'] . '/csm/' ); require_once( BASEPATH . 'includes/core.php' ); // Here it is no problem, but after this ... blah blah !!! ?> Please help... Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 3, 2011 Share Posted September 3, 2011 Its showing the path in my site-available settings. What exactly would that value be, because it's the most likely reason for the problem you are having (i.e. including a file using a URL/URI instead of a file system path)? Quote Link to comment Share on other sites More sharing options...
etdsbastar Posted September 3, 2011 Author Share Posted September 3, 2011 Its showing the path in my site-available settings. What exactly would that value be, because it's the most likely reason for the problem you are having (i.e. including a file using a URL/URI instead of a file system path)? Oh ! how to solve the problem, please tell... Here is my site-available setting: <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot [PATH TO MY FOLDER WHERE I AM HAVING MY WWW FILES] <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory [PATH TO MY FOLDER WHERE I AM HAVING MY WWW FILES]> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 3, 2011 Share Posted September 3, 2011 You have yet to provide us with any information that identifies where the problem is occurring at. 'most likely' means something is at the top of the list. It does not mean that is the cause of the problem. Quote Link to comment Share on other sites More sharing options...
etdsbastar Posted September 3, 2011 Author Share Posted September 3, 2011 You have yet to provide us with any information that identifies where the problem is occurring at. 'most likely' means something is at the top of the list. It does not mean that is the cause of the problem. PLEASE HAVE A LOOK AT THE MODIFIED POST ABOVE... Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 3, 2011 Share Posted September 3, 2011 That doesn't show us what the $_SERVER['DOCUMENT_ROOT'] value is so that someone could actually determine if it is the cause of the problem. Quote Link to comment Share on other sites More sharing options...
etdsbastar Posted September 3, 2011 Author Share Posted September 3, 2011 That doesn't show us what the $_SERVER['DOCUMENT_ROOT'] value is so that someone could actually determine if it is the cause of the problem. The value of $_SERVER['DOCUMENT_ROOT'] is /home/abc/server Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 3, 2011 Share Posted September 3, 2011 Finally, at least that eliminates the $_SERVER['DOCUMENT_ROOT'] variable as the cause of the problem. At this point, you would need to post enough of your code that duplicates the problem (if the exact code you post does not duplicate the error, don't waste time posting it) if you want someone to help further and is there any chance you have multiple include/core.php folders/files at different starting paths, some with and some without the define() statements and you might be including the wrong one? Also, why are you using require_once instead of require (php has had a number of bugs in the _once versions)? Quote Link to comment Share on other sites More sharing options...
etdsbastar Posted September 3, 2011 Author Share Posted September 3, 2011 Finally, at least that eliminates the $_SERVER['DOCUMENT_ROOT'] variable as the cause of the problem. At this point, you would need to post enough of your code that duplicates the problem (if the exact code you post does not duplicate the error, don't waste time posting it) if you want someone to help further and is there any chance you have multiple include/core.php folders/files at different starting paths, some with and some without the define() statements and you might be including the wrong one? Also, why are you using require_once instead of require (php has had a number of bugs in the _once versions)? I had done replacing all the require_once with require directive. Secondly, there is no other file naming core.php in the include directory. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 3, 2011 Share Posted September 3, 2011 Without actual code to test with that reproduces the problem, sorry, but you cannot be helped. Why are you not cooperating when someone is trying to help you? You are doing something in your code on your server that does not work and you want someone who is not standing right next to you to help you troubleshoot what your code is doing, but without actually having enough of the code that reproduces the problem. This is like you have a dead battery in your car and someone stopped to give you a jump start and you refuse to open the hood of your car. I'm going to make a wild guess. You originally had the paths hard-coded into your logic and have just recently added the defined constant, but the core.php file never got edited/saved to the correct actual folder so it does not have the define() statements in it but the files that are being required did get edited/saved to the correct actual folder, so they are attempting to reference the defined constant, but the file where the defined constant should be at is the old code without the defined constant. Quote Link to comment Share on other sites More sharing options...
etdsbastar Posted September 3, 2011 Author Share Posted September 3, 2011 Without actual code to test with that reproduces the problem, sorry, but you cannot be helped. Why are you not cooperating when someone is trying to help you? You are doing something in your code on your server that does not work and you want someone who is not standing right next to you to help you troubleshoot what your code is doing, but without actually having enough of the code that reproduces the problem. This is like you have a dead battery in your car and someone stopped to give you a jump start and you refuse to open the hood of your car. I'm going to make a wild guess. You originally had the paths hard-coded into your logic and have just recently added the defined constant, but the core.php file never got edited/saved to the correct actual folder so it does not have the define() statements in it but the files that are being required did get edited/saved to the correct actual folder, so they are attempting to reference the defined constant, but the file where the defined constant should be at is the old code without the defined constant. Sorry, I am really sorry, i couldn't want to hurt you. I am sending you the zip coded file of my project. Please help me. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
etdsbastar Posted September 3, 2011 Author Share Posted September 3, 2011 Please help.... Quote Link to comment Share on other sites More sharing options...
etdsbastar Posted September 3, 2011 Author Share Posted September 3, 2011 is there anyone to help me please Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 3, 2011 Share Posted September 3, 2011 The code you posted works for me. Again, the most likely problem is that your actual $_SERVER['DOCUMENT_ROOT'] value is a URL (http://something) so that the files are being included/required through a URL instead of through the file system. Echo $_SERVER['DOCUMENT_ROOT'] in the index.php file to see what it is. Quote Link to comment Share on other sites More sharing options...
etdsbastar Posted September 3, 2011 Author Share Posted September 3, 2011 It is showing the path to my localhost directory ie. /home/abc/server Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted September 3, 2011 Share Posted September 3, 2011 The code is including core.php and core.php is including common.php (based on the last error message you posted.) The next most likely problem is that in your common.php file, the name BASEPATH has been corrupted. I would delete and then re-type BASEPATH to see if that corrects the problem. Delete and re-type the white-space before and after BASEPATH as well. Quote Link to comment Share on other sites More sharing options...
etdsbastar Posted September 3, 2011 Author Share Posted September 3, 2011 The code is including core.php and core.php is including common.php (based on the last error message you posted.) The next most likely problem is that in your common.php file, the name BASEPATH has been corrupted. I would delete and then re-type BASEPATH to see if that corrects the problem. Delete and re-type the white-space before and after BASEPATH as well. This is what I am getting: Notice: Use of undefined constant BASEPATH - assumed 'BASEPATH' in /home/abc/server/csm/includes/error.php on line 31 Notice: Undefined variable: _LF in /home/abc/server/csm/includes/error.php on line 44 where ever the word $_LF and BASEPATH came. Do you want some setting details from Apache2 or PHP5 Quote Link to comment Share on other sites More sharing options...
etdsbastar Posted September 3, 2011 Author Share Posted September 3, 2011 pls help Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted September 3, 2011 Share Posted September 3, 2011 Users should not "bump" topics that are still on the first page of the forums. If you bump' date=' you must provide additional information. If you resort to bumping, chances are your question needs to be re-thought and re-described (see Eric Raymond's "How To Ask Questions The Smart Way").[/quote'] Quote Link to comment 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.