Click to See Complete Forum and Search --> : Best way to do a header script? PHP.


Nibinaear
January 22nd, 2005, 06:36 AM
I've been trying to make a script to act as a header to add in to my webpages. I have the code in html working fine. I now need to convert it to php that prints out the code, how do I do this in a simple and easy way?

I've tried converting all double quotes to \" so that when I use echo "", it escapes them. This doesn't seem to work, do I need another method? Obviously I need it in a seperate file I can import. The book I have recommends using .inc files. The only thing is that I've heard that there can be security issues when using those, in that when errors are detected, the user could potentially see your script.

I've seen another method where php functions were used and called from the main php file, at the moment that seems the most likely option.

visualAd
January 22nd, 2005, 07:46 AM
Use include (http://www.php.net/include). There is no need to use echo or escape the quotes. It will just dump the HTML if you have no <?php ?> tags.

visualAd
January 22nd, 2005, 07:52 AM
Read the reply I gave you in the other post (http://www.codeguru.com/forum/showthread.php?p=1082312#post1082312).


When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags (http://uk.php.net/manual/en/language.basic-syntax.php#language.basic-syntax.phpmode).

Nibinaear
January 22nd, 2005, 08:46 AM
USELESS, MODERATOR PLEASE DELETE.

Nibinaear
January 22nd, 2005, 08:59 AM
Okay, so now I have my header working in that it is just a html file now, for some reason I thought it had to be a php. But the trouble is, I've done my homepage in php, with html afterwards, and it fails to print, I'm still missing something.


<?php
include ('header.html');
?>

<!--Modules row-->
<tr>
<td width =\"200\" rowspan = \"5\" align = \"center\" valign = \"top\"><img src = \"corkboard.jpg\"/></td>

<td width =\"50%\" rowspan = \"5\">
<table border = \"1\" cellpadding = \"0\" cellspacing = \"0\" valign = \"top\" width = \"100%\" height = \"100%\">
<tr>
<td valign = \"top\" width = \"100%\" height = \"100%\">
Welcome to testing times.
<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;<P>&nbsp;

</td>
</tr>
</table>
</td>

<td>&nbsp;</td>
<td class = \"twohundred\" colspan = \"3\" align = \"right\">
<img src= \"tornpaper.jpg\"/>
</td>
</tr>

<tr>
<td>&nbsp;</td>
<td class = \"twohundred\" colspan = \"3\" name = \"modules box\">

<table width = \"100%\" background = \"bg01.jpg\" height = \"100%\" border = \"1\" cellpadding = \"0\" cellspacing = \"0\">
<tr>
<td>
<ul type = \"square\">
<li/>CG115: E-Business & Web Management
<li/>CG551: Professional Development
<li/>CM512: Object Orientation
</ul>
</td>
</tr>
</table>

</td>
</tr>

<tr height = \"30\">
<td colspan = \"4\" name = \"right hand side\">&nbsp;</td>
</tr>



<!--tasks-->
<tr>
<td>&nbsp;</td>
<td class = \"twohundred\" width = \"200\" colspan = \"3\" name = \"right hand side\" align = \"right\">
<img src= \"tornpaper-tasks.jpg\"/>
</td>
</tr>

<tr>
<td>&nbsp;</td>
<td class = \"twohundred\" name = \"right hand side\" colspan = \"3\">
<table width = \"100%\" height = \"100%\" background = \"bg01.jpg\" border = \"1\" cellpadding = \"0\" cellspacing = \"0\">
<tr>
<td class = \"twohundred\">
<ul type = \"square\">
<li/>Add Assignment
<li/>Edit Assignment
<li/>Edit my details
<li/>Change my details
</ul>
</td>
</tr>
</table>
<P>&nbsp;<P>&nbsp;<P>&nbsp;
</td>
</tr>


</table>

</body>

</html>


EDIT: DOH, FORGOT TO TAKE OUT THE ESCAPED QUOTES!

Nibinaear
January 22nd, 2005, 09:15 AM
Sorry to visualad for being a bit thick over this issue, I've sorted the scripts out now. For some reason I wasn't getting told via email that I had replies in the other post.

Dia
January 28th, 2005, 04:26 AM
Assalam u Alaikum,
I perhaps didn't get it right or what... or don't know whether your problem got resolved or not... but why don't you simply replace all the inner double quotes with single quotes so that there is no conflict between ' and "!

I mean, instead of
<td width =\"200\" rowspan = \"5\" align = \"center\" valign = \"top\"><img src = \"corkboard.jpg\"></td>

why don't you use.....
<td width='200' rowspan='5' align='center' valign='top'><img src='corkboard.jpg'></td>

or even....
<td width=200 rowspan=5 align=center valign=top><img src='corkboard.jpg'></td>
(coz we DON'T need quotes in HTML if the possible values are built-in or numeric)

Still sorry, if i misunderstood!


Take care & Allah Hafiz
~Dia

visualAd
January 28th, 2005, 04:32 AM
The reason why is because it would then not be valid HTML. Well formed, valid HTML uses double quotes. My point is there is absolutely no need to use an echo statement. Just go out of PHP mode using the ?> tag.

Dia
January 28th, 2005, 05:21 AM
Yeah, that's what I myself do... exiting from PHP mode when any HTML needs to be inserted but now what I really want to know is that

does it really matter if you write *valid* HTML code using those scary double quotes unless it's absolutely essential? I mean, almost all the browsers worldover are now intelligent at least to the extent as to recognize HTML in any form... your browser will print out all the HTML code even if you have no starting <html> tags?

No offence is meant if you are really a dont-miss-a-single-rule-or-convention programmer :p

visualAd
January 28th, 2005, 12:17 PM
Yeah, that's what I myself do... exiting from PHP mode when any HTML needs to be inserted but now what I really want to know is that

does it really matter if you write *valid* HTML code using those scary double quotes unless it's absolutely essential? I mean, almost all the browsers worldover are now intelligent at least to the extent as to recognize HTML in any form... your browser will print out all the HTML code even if you have no starting <html> tags?

No offence is meant if you are really a dont-miss-a-single-rule-or-convention programmer :p
I could say does it really matter if you miss a quote of a curly brace in PHP and your answer would be yes. As with any language its about context. Having a strict set of ruls means that there is no confusion in context. This was one of the main failings of the early versions of HTML.

You're right; if you forget to put in a quote in HTML the browser will be smart enough to compensate for it. But you then run the risk of the browser miss interpreting your HTML code, for example:

<A href=mydocs/file with a space.html>My File</a>


As you have missed out the quotes the browser will actually now link to mydocs/file. For this reason using well formed and correct HTML makes rendering easier for the browser and allows you to ensure your pages are displayed correctly.