Jump to content

[SOLVED] No include..?


ItsWesYo

Recommended Posts

Need to Know:

http://example.site.com/a/includes/header.php (Would contain the header)

http://example.site.com/a/includes/footer.php (Would contain the footer)

http://example.site.com/a/index.php (The index page of directory A)

http://example.site.com/a/lettera/index.php (Another index of a higher directory)

 

The Problem:

Okay. It won't display my header and footer even though I correctly use the include function. I've tried everything, but just displays a white page with the text.

 

Example:

Let's say I make a page with a url of http://example.site.com/a/lettera/index.php.

And I want to include http://example.site.com/a/includes/header.php and http://example.site.com/a/includes/footer.php

So, I would use the PHP include function and use those.

The problem is, the includes won't show up, just the page of /a/lettera/index.php.

 

Help?

Link to comment
Share on other sites

Okay, sorry about that..I'll post a quick example...

 

http://example.site.com/a/includes/header.php

<b>This is my header text example</b>

 

http://example.site.com/a/includes/footer.php

<b>This is my footer text example</b>

 

http://example.site.com/a/index.php

<?php
include 'http://example.site.com/a/includes/header.php';
?>

text would go here

<?php
include 'http://example.site.com/a/includes/footer.php';
?>

 

http://example.site.com/a/lettera/index.php

<?php
include 'http://example.site.com/a/includes/header.php';
?>

text would go here

<?php
include 'http://example.site.com/a/includes/footer.php';
?>

 

 

Now of course, if you were to display the /a/letter/index.php page, it would show:

 

This is my header text example

text would go here

This is my footer text example

 

But it only shows 'text would go here'

Link to comment
Share on other sites

include './includes/header.php';

 

Try that.

 

Note that I tooke the /a out of the path.

 

Also, try using require(); instead of include so you can get an error message to pop up telling you why the file couldn't be included, if it can't be.

 

When you get it working, you can change it back to include.

 

Hope that helps...

Link to comment
Share on other sites

Personally I almost always use absolute paths. Typically it will be something like:

/home/username/www/blah/file.php

 

If you're going to use it one level up, here's what I would do:

define('PATH', str_replace('lettera','',dirname(__FILE__)).'includes/');
include PATH.'header.php';

 

Same thing as above, just broken down into manageable chunks:

<?php
// Get the current path
$currentPath = dirname(__FILE__);

// Strip out the top folder (if it exists)
$strippedPath = str_replace('/lettera','',$currentPath);

// And instead, add in the includes
$includePath = $strippedPath.'/includes/';

// Now use the variable in your include
include $includePath.'header.php';
?>

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.