Jump to content

php includes explanation


delphi123

Recommended Posts

Ok, let's say I have some files:

 

index.php

/includes/header.php

/includes/images/logo.jpg

 

Now the logo appears in the header.php file and the header.php appears in the index.php file.

 

I've been using things like:

<?php require_once('includes/header.php'); ?>

 

but it doesn't appear to work in all instances - is there a limit on the number of nested includes?

Link to comment
Share on other sites

No there isn't a limit.  Firstly, avoid using

 

require_once();

 

instead use

 

require();

 

It basically does the same thing and uses less resources.

 

When you say it doesn't work, what exactly doesn't it do?  Does it not show any of the content in the include file at all?

Link to comment
Share on other sites

ok, require it is!

 

Well I'm building a site and I'm trying to build a 'template' file for all the pages - ie so a) it's simpler and b) easier to update.

 

I want to for example include the header, footer and layout info using an include and then be left with simply the actual content needing written.

 

The way I do it at work (using ASP mind you!) is say to specify the CSS I have an introductory slash for the root - so for the css it'd be something like:

 

/css/styles.css

 

This'll work in all directories.

 

Now this doesn't work on my one (I 'think' this could be because I'm on shared hosting and / tries to specify the root of the server.

 

So I then created a variable with my server location in it:

 

$server = "http://www.test.com/";

 

And I then concatenate using an ugly-bugly line like:

 

<?php include($root."test/mysql_connect.php"); ?>

 

However this still requires me to specify the server root in each file!

 

Can anyone explain how they do this?

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.