Jump to content

[SOLVED] include error but every thing looks sweet as?


supergrame

Recommended Posts

<?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?

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");
?>

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

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

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.

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()

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

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" />

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

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

 

:)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.