Jump to content

php include, within php include


Jodz

Recommended Posts

I'm using ajax so that a website im designing doesnt refresh when u navigate around it. http://www.eactestsite.com/web/kumba

it calls information from a file called ajaxcontent.php and is displayed via a php include the the index.php file. Thing is when i use an include within the ajaxcontent.php the page breaks and will only load up to the point where the include is in the index file. I just can't seem to get it to work.

Any help would be much appreciated!

cheers,
Jodz.
Link to comment
https://forums.phpfreaks.com/topic/34394-php-include-within-php-include/
Share on other sites

My guess is that the path / filename you've passed to the include construct is not correct.  Is ajaxcontent.php in the same directory as index.php?  If it's not then the includes within ajaxcontent.php must be relative to index.php not ajaxcontent.php.  I'll try to be illustrate this with a small example.

Consider a directory structure like this:

/root/index.php
/root/src/somescript.php
/root/lib/someclass.php

[b]index.php[/b]
[code]
<?php
include('src/somescript.php');
// ..
?>
[/code]

[b]somescript.php[/b]
[code]
<?php
// This won't work, as it's relative to somescript.php
// include('../lib/someclass.php');

// This will because it's relative to index.php.
include('lib/someclass.php');
?>
[/code]

Generally I find it easier to include everything in one file on the root directory.

[b]global.php[/b]
[code]
<?php
include('lib/someclass.php');
include('lrc/somescript.php');
?>
[/code]

I hope this helps.

Best,

Patrick

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.