supergrame Posted March 19, 2009 Share Posted March 19, 2009 <?php include("includes/header.php"); include("includes/links.php"); include("registerhtml.php"); include("../includes/footer.php"); ?> header.php and links.php are in the same DIR here is the error Warning: include(includes/header.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\site\register\register.php on line 10 Warning: include() [function.include]: Failed opening 'includes/header.php' for inclusion (include_path='.;C:\php5\pear') in C:\wamp\www\site\register\register.php on line 10 i have no idea why this is causing an error logically everything is OK although i did read somewhere something about the includes folder! like permissions but that only applys to a live server right? ??? any ideas? Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/ Share on other sites More sharing options...
rhodesa Posted March 19, 2009 Share Posted March 19, 2009 What is the folder structure of all these files? Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-788549 Share on other sites More sharing options...
supergrame Posted March 19, 2009 Author Share Posted March 19, 2009 here is the screen shot hope this helps [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-788557 Share on other sites More sharing options...
rhodesa Posted March 19, 2009 Share Posted March 19, 2009 ok...so...you are loading up /register/register.php in your browser? wouldn't it be <?php include("../includes/header.php"); include("../includes/links.php"); include("registerhtml.php"); include("../includes/footer.php"); ?> Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-788567 Share on other sites More sharing options...
supergrame Posted March 19, 2009 Author Share Posted March 19, 2009 yes that is correct.. Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-788574 Share on other sites More sharing options...
supergrame Posted March 19, 2009 Author Share Posted March 19, 2009 ok im getting somewere i got the header included well i think so becuase it changed its error to this Warning: require_once(./mysql/db_connect.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\site\includes\header.php on line 1 Fatal error: require_once() [function.require]: Failed opening required './mysql/db_connect.php' (include_path='.;C:\php5\pear') in C:\wamp\www\site\includes\header.php on line 1 i have an include in my header for the database so really is should include the header and have the database connected, i have the same for the login and no database issues Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-788584 Share on other sites More sharing options...
supergrame Posted March 19, 2009 Author Share Posted March 19, 2009 ok i no whats going on but im not sure how to fix it, in the header i have include(./db_connect); and that works fine for the login but not for the registration but if i change it to this include(../db_connect); it works for the registration but not the login, so it has something to do with were i am storing the db_connect.php, i guess i need to put it in a DIR that is the same folders deep as the registration and login. maybe Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-788589 Share on other sites More sharing options...
supergrame Posted March 19, 2009 Author Share Posted March 19, 2009 ok i found a solution i just copped the header.php and put it in an includes folder in the registration folder, that is kind of a nasty fix tho consider the hole point of me wanting to try using includes was to have the cascading effect, so if any can think of a much practical way im all ears. Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-788597 Share on other sites More sharing options...
rhodesa Posted March 19, 2009 Share Posted March 19, 2009 if you are including files from include files you will run into this problem. include() finds the file relative to the script calling it, which could be anywhere. so, in your include files, like header.php, include db_connect like so: <?php include(dirname(__FILE__).'/../includes/db_connect.php'); ?> dirname(__FILE__) will return the full path to the current file this code is in (aka header.php), even if the parent script is somewhere else. also, you may want to read up on the differences between include/include_once/require/require_once. usually for things like db connections you would want require_once() Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-788618 Share on other sites More sharing options...
supergrame Posted March 20, 2009 Author Share Posted March 20, 2009 hey thank you very much that does work, but now i have to change the images to the header same issue, so i think i should just restructure my DIR's im really new at this just trying to find a structure that works for me, i see most people put there db_connect.php in the includes folder i have mine in mysql folder i might change so its in the includes folder everyone else seems to be doing that thank you for your help Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-789039 Share on other sites More sharing options...
rhodesa Posted March 20, 2009 Share Posted March 20, 2009 as far as web content like images...you can either set a config with the 'prefix' or use a <base> tag. for the prefix, just set a global variable...let's call it $url_prefix. if you site was at http://yourdomain.com/folder/index.php, and your images were in http://yourdomain.com/folder/images/ your 'prefix' would be '/folder'...and your code would look like: <img src="<?php echo $url_prefix; ?>/myimage.jpg" /> Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-789048 Share on other sites More sharing options...
supergrame Posted March 20, 2009 Author Share Posted March 20, 2009 ahh thanks that will work nicely but what do you think of my file structure i have its in the screenshot above. Is that a common DIR and FILE structure? Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-789061 Share on other sites More sharing options...
rhodesa Posted March 20, 2009 Share Posted March 20, 2009 i would put anything that is an include in the include directory. then, in that folder, make a file called '.htaccess' and put in it: deny from all this will prevent any files in that folder (and sub folders) from being accessed via the web. PHP will still have access to these files though Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-789063 Share on other sites More sharing options...
supergrame Posted March 20, 2009 Author Share Posted March 20, 2009 ahh, i have read about that somewhere yea i will do that once i put it on a live server, for the time being this is a site i want to keep but also a good training thing for me, thanks for your help much appreciated Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-789067 Share on other sites More sharing options...
rhodesa Posted March 20, 2009 Share Posted March 20, 2009 no problem...good luck! Link to comment https://forums.phpfreaks.com/topic/150156-solved-include-error-but-every-thing-looks-sweet-as/#findComment-789079 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.