liamC 
Member 
 
Registered: 28th Feb 04
 
User status: Offline 
 
 | 
 
I have made a header file called header.php 
 
I have made an index.php file and want the top of index.php to show the text/image that is in header.php. I have added this code; 
 
code: <?php include ($_SERVER['DOCUMENT_ROOT'].'header.php') ?>
  
  
 
I keep getting this error: 
 
quote:   
Fatal error: Call to a member function on a non-object in /home/.saggy/username/domain.com/site/header.php on line 51
   
 
Anyone know where I'm going wrong? 
 
[Edited on 23-11-2006 by liamC] 
 
[Edited on 23-11-2006 by liamC]
 | 
PaulW 
Member 
 
Registered: 26th Jan 03
 Location: Atherton, Greater Manchester 
User status: Offline 
 
 | 
 
meh you edited 
 
issue is a problem in the header.php file (line 51 as it says), not with the include statement itself 
 
[Edited on 23-11-2006 by PaulW]
 | 
liamC 
Member 
 
Registered: 28th Feb 04
 
User status: Offline 
 
 | 
 
There is no line 51 mate, that's the problem! 
 
Basically I'm just doing a test site to get it working! 
 
In header.php I have a link to www.yahoo.com 
 
In index.php, I have the code above, and a word saying 'test'! 
 
 
 | 
PaulW 
Member 
 
Registered: 26th Jan 03
 Location: Atherton, Greater Manchester 
User status: Offline 
 
 | 
 
post the code contained in header.php here
 | 
Doug 
Member 
 
Registered: 8th Oct 03
 
User status: Offline 
 
 | 
 
Post the code up from your header.php file. 
 
i bet you have forgotten to put a ; in there somewhere!
 | 
liamC 
Member 
 
Registered: 28th Feb 04
 
User status: Offline 
 
 | 
 
yay! I got it working; my first bit of PHP Code   
 
Basically, I've put a link to yahoo.com in the header.php file, and put the word 'test' in index.php  
 
Here is the code for both pages for future help for anyone. 
 
HEADER.PHP 
 
code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
<title>Untitled Document</title> 
<style type="text/css"> 
<!-- 
body { 
	margin-left: 0px; 
	margin-top: 0px; 
} 
--> 
</style></head> 
<body> 
<a href="www.yahoo.com" target="_blank">www.yahoo.com</a> 
</body> 
</html>
  
  
 
INDEX.PHP 
 
code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
<title>Untitled Document</title> 
<style type="text/css"> 
<!-- 
body { 
	margin-left: 0px; 
	margin-top: 0px; 
} 
--> 
</style></head> 
 
<body> 
<?php include ($_SERVER['DOCUMENT_ROOT'].'/header.php') ?> 
<br /> 
test 
</body> 
</html>
  
  
 
[Edited on 23-11-2006 by liamC]
 | 
Steve 
Premium Member
 
Registered: 30th Mar 02
 Location: Worcestershire             Drives: Defender 
User status: Offline 
 
 | 
 
theres no php in the header file lol
 | 
liamC 
Member 
 
Registered: 28th Feb 04
 
User status: Offline 
 
 | 
 
I wasn't bothered about that mate, I just wanted the index.php page displaying whatever was in the header.php file. 
 
New to it, so just having a play around 
 
  
 | 
drax 
Member 
 
Registered: 5th Feb 05
 Location: Sittingbourne, Kent 
User status: Offline 
 
 | 
 
You're better off including content from pages,  INTO a template, rather than calling a template file into a content file
 | 
John 
Member 
 
Registered: 30th Jun 03
 
User status: Offline 
 
 | 
 
Where did you find the best for learning php liam? 
 
Just looking about google?
 | 
Steve 
Premium Member
 
Registered: 30th Mar 02
 Location: Worcestershire             Drives: Defender 
User status: Offline 
 
 | 
 
you need to call it as a template, and parse it anything in an include will try and read that file as php and that file isnt php hence why your getting the error 
 
[Edited on 23-11-2006 by Steve]
 | 
drax 
Member 
 
Registered: 5th Feb 05
 Location: Sittingbourne, Kent 
User status: Offline 
 
 | 
 
What are you talking about? I include .php's all the time which dont have PHP in
 | 
Steve 
Premium Member
 
Registered: 30th Mar 02
 Location: Worcestershire             Drives: Defender 
User status: Offline 
 
 | 
 
what i mean is, simply by including that file it wont display on your page until you actually output it as an array and parse it 
 
[Edited on 23-11-2006 by Steve]
 | 
liamC 
Member 
 
Registered: 28th Feb 04
 
User status: Offline 
 
 | 
 
John; yes, just be looking about google. 
 
Steve; that piece of coding works fine to display things from the header.php file   
 
I will have a flash animation and a list of links in header.php and it will save putting them all in each file. 
 
There won't be anything wrong with doing that? 
 | 
Steve 
Premium Member
 
Registered: 30th Mar 02
 Location: Worcestershire             Drives: Defender 
User status: Offline 
 
 | 
 
yes but when you try and include it, unless you tell it to output to the browser it wont do anything or you'l get errors. 
 
Basically when you incldue it it wil read whats in that file, and do nothing until you tell it to. 
 
In this case you want to either output elements from an array, or just output it straight to the browser using parse
 | 
Doug 
Member 
 
Registered: 8th Oct 03
 
User status: Offline 
 
 | 
 
quote: Originally posted by John 
Where did you find the best for learning php liam? 
 
Just looking about google? 
   
 
www.freewebmasterhelp.com has some good tutorials  
 | 
Steve 
Premium Member
 
Registered: 30th Mar 02
 Location: Worcestershire             Drives: Defender 
User status: Offline 
 
 | 
 
i always learn from messing about with it myself, i cannt learn anything from reading stuff, iv always been shit at exams for this reason, when my teachers said i should be getting a's i was coming away with b's and c's, but i was actually better than some of the kids coming away with a's 
 
[Edited on 23-11-2006 by Steve]
 | 
ed 
Member 
 
Registered: 10th Sep 03
 
User status: Offline 
 
 | 
 
quote: Originally posted by John 
Where did you find the best for learning php liam? 
 
Just looking about google? 
  php.net or codewalkers.com...
 | 
drax 
Member 
 
Registered: 5th Feb 05
 Location: Sittingbourne, Kent 
User status: Offline 
 
 | 
 
I reverse engineer things
 | 
Steve 
Premium Member
 
Registered: 30th Mar 02
 Location: Worcestershire             Drives: Defender 
User status: Offline 
 
 | 
 
if you want to twait til later il write what you need to add to your code.
 | 
AndyKent 
Member 
 
Registered: 3rd Sep 05
 
User status: Offline 
 
 | 
 
Steve, that code works fine - my website php-includes are written just like that and everything is output fine without any extra function calls???
 | 
Steve 
Premium Member
 
Registered: 30th Mar 02
 Location: Worcestershire             Drives: Defender 
User status: Offline 
 
 | 
 
i bung the info from the include into a variable then output the page, means you can add elements of the page as an array, IMO that is a better way of doing it as you can adjust things quickly and site wide if you need to 
 
[Edited on 24-11-2006 by Steve]
 | 
AndyKent 
Member 
 
Registered: 3rd Sep 05
 
User status: Offline 
 
 | 
 
I have mine set-up with various useful features, page layouts, log-in/out processes etc. in various functions. I include a whole PHP page - user_access.php for example - and then call the functions as needed. 
 
Actually, I see what you mean now....you can't just bung everything at the top and hope it works as that makes it more complicated......I get you now!
 | 
Steve 
Premium Member
 
Registered: 30th Mar 02
 Location: Worcestershire             Drives: Defender 
User status: Offline 
 
 | 
 
uh huh
 | 
liamC 
Member 
 
Registered: 28th Feb 04
 
User status: Offline 
 
 | 
 
The purpose that I would need it for is fine though surely? 
 
If I make a whole website, and put the navigation links on every single page, surely making a header page with all the links on saves me loads of time as I only have to change one page?  
 |