delphi123 Posted December 20, 2007 Share Posted December 20, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/82541-php-includes-explanation/ Share on other sites More sharing options...
p2grace Posted December 20, 2007 Share Posted December 20, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/82541-php-includes-explanation/#findComment-419618 Share on other sites More sharing options...
delphi123 Posted December 21, 2007 Author Share Posted December 21, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/82541-php-includes-explanation/#findComment-420467 Share on other sites More sharing options...
PFMaBiSmAd Posted December 21, 2007 Share Posted December 21, 2007 Because an include/require uses a file system path, the leading slash refers to the root of the current hard disk instead of the document root. See this post for how to do what you want - http://www.phpfreaks.com/forums/index.php/topic,172711.msg766014.html#msg766014 Quote Link to comment https://forums.phpfreaks.com/topic/82541-php-includes-explanation/#findComment-420475 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.