krysco Posted January 7, 2009 Share Posted January 7, 2009 I'm trying to do something really simple and I can't quite figure out how. I want to use php to include my header document the best way possible. I want it to pull in another "page" that has the code for my document top in it. I tried three ways (none of them worked). I tried creating a page called header.php with the document in it that looked like the following. <html> <body> <img src="images/includes/headers/header.php"> </body> </html> That didn't work so I tried this. <html> <body> <img src="<?php echo('./includes/headers/header.php')"> </body> </html> That didn't work either. So tried both again this time using a .html extension instead of php......nope. So then I tried using just the jpeg itself.... <?php include('./includes/headers/images/header.jpg')?> I got a parse error: Parse error: syntax error, unexpected T_STRING in /var/www/includes/headers/images/header.jpg on line 39 Ummmmmm why is there a line 39 in a jpeg image??? I have no idea what I'm doing or what to try next. Help! Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/ Share on other sites More sharing options...
rhodesa Posted January 7, 2009 Share Posted January 7, 2009 um...i'm confused...is it header.php or header.jpg? are you just trying to do this: <html> <body> <?php include("images/includes/headers/header.php"); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731742 Share on other sites More sharing options...
krysco Posted January 7, 2009 Author Share Posted January 7, 2009 You're probably confused because I don't really know what I'm doing and I sort of lost track of what I did. I'm not so much concerned as fixing what's wrong as I am with doing what's right or what works. What I am trying to achieve is this. I want to have a page with my header on it. I want to be able to include that page at the top of the rest of the pages in my site so that if I want to change the header I only have to change it in one place. I am also going to use this method for my nav menu. What would be the best way to do it? When I used to do it with coldfusion it was as simple as creating an html page without the html and body tags (just a table) and throwing a cf include function at the top of every page. How would I do that? Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731759 Share on other sites More sharing options...
jonsjava Posted January 7, 2009 Share Posted January 7, 2009 You're probably confused because I don't really know what I'm doing and I sort of lost track of what I did. I'm not so much concerned as fixing what's wrong as I am with doing what's right or what works. What I am trying to achieve is this. I want to have a page with my header on it. I want to be able to include that page at the top of the rest of the pages in my site so that if I want to change the header I only have to change it in one place. I am also going to use this method for my nav menu. What would be the best way to do it? When I used to do it with coldfusion it was as simple as creating an html page without the html and body tags (just a table) and throwing a cf include function at the top of every page. How would I do that? ok, so the header is basically HTML, right? if so, then doing this includes files: <?php include("include_file.php"); ?> <!-- continue as normal --!> Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731762 Share on other sites More sharing options...
.josh Posted January 7, 2009 Share Posted January 7, 2009 Example: ./index.php ./includes/headers/header.php ./includes/headers/images/header.jpg index.php <body> <?php include "includes/headers/header.php"; ?> </body> header.php <img src = '/includes/headers/images/header.jpg' /> if all header.php is doing is echoing out html, you can rename it header.html. Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731769 Share on other sites More sharing options...
krysco Posted January 7, 2009 Author Share Posted January 7, 2009 so my header.php or header.html file doesn't need the <html> or <body> tags? Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731772 Share on other sites More sharing options...
.josh Posted January 7, 2009 Share Posted January 7, 2009 no. Those would be in index.php. When you include one thing in another, it's just like copy/pasting it inside it. When you request index.php, it is the same as it being this (minus the comments; i put them there for notes): <body> // came from index.php <img src = '/includes/headers/images/header.jpg' /> // came from header.html/php </body> // came from index.php Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731775 Share on other sites More sharing options...
krysco Posted January 7, 2009 Author Share Posted January 7, 2009 Right. I think this is one of the things I tried. I'm going to give it another shot and let you know if it works or not. Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731778 Share on other sites More sharing options...
krysco Posted January 7, 2009 Author Share Posted January 7, 2009 That didn't work either. I'm on the computer I was having the problem with. When I open the page in firefox, everything works except the header. It only shows the background color I set in my CSS. These are the two files I'm working with. index.php <!DOCTYPE html PUBLIC "-//w3C//DTD XHTML 1.0 Strict//en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>CSS Practice</title> <link href="includes/css/style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div id="container"> <div id="pageHeader"> <?php include('./includes/headers/header.html');?> </div> <div id="contentContainer"> <div id="content"> <p>Content</p> </div> </div> <div id="sidebarContainer"> <div id="navcontainer"> <ul> <li><a href="testcss.html" id="current>Page 1</a></li> <li><a href="http://www.google.com">Page 2</a></li> <li><a href="http://www.yahoo.com">Page 3</a></li> <li><a href="http://www.altavista.com">Page 4</a></li> </ul> </div> </div> <div id="footer" class="clearer"> <p>Footer</p> </div> </div> </body> </html> header.html <img src="/images/header.jpg"> Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731785 Share on other sites More sharing options...
.josh Posted January 7, 2009 Share Posted January 7, 2009 well probably your path is wrong. Inside headers.html you are putting the image path relative to where headers.html is, but that won't work when it's being included into a file somewhere else. The relative path would be from the file that's including it. Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731798 Share on other sites More sharing options...
krysco Posted January 7, 2009 Author Share Posted January 7, 2009 yeah you were right it looks like the file path is wrong. I put everything in the same folder and it works fine. I'll have to figure out what's going on with the file paths but thanks for the help! Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731813 Share on other sites More sharing options...
xangelo Posted January 7, 2009 Share Posted January 7, 2009 Nothings really going on with the file paths. You just have to realize that when it gets included into another file, the relative paths are no longer the same, since the file has moved. Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731818 Share on other sites More sharing options...
krysco Posted January 7, 2009 Author Share Posted January 7, 2009 yes i understand how that works. the file path i used is relative to where the document lies coupled with the fact that the index page is at the site root. is there a command i can use to get directly back to the site root? i know with cf it was a complicated string of like ./../../../../../../../../ lol Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731828 Share on other sites More sharing options...
.josh Posted January 7, 2009 Share Posted January 7, 2009 you could always use an absolute path : http://www.mysite.com/includes/headers/images/header.jpg Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731829 Share on other sites More sharing options...
krysco Posted January 7, 2009 Author Share Posted January 7, 2009 i tried that too. the only thing that seems to work is having the header image and the header html page in the same folder as the index page. is there something like a BASE HREF that I could use. i remember something like that in coldfusion but i don't remember how it worked. could the problem be that i'm using a VM (doubt it). i have it set up so that my VM gets the same ip address as the host machine. i don't think that would cause a problem since when i tried the absolute url i used http://localhost. that should take it to my site root. but anybody know anything about the BASE HREF? Quote Link to comment https://forums.phpfreaks.com/topic/139867-another-parse-error/#findComment-731837 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.