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?

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.