Scripting: A little php help

started by Maia on Jan 5, 2004 — RSS Feed

Maia Maia
Posts: 4

I am very new to writing php (if "writing" is the correct word). I wanted to make a small include script for headers where I could change one page and see the effects across my site, but have the actual text for the header on the individual pages. So I threw this together. I'd like to know if there are serious bugs here, or if this is a unsafe/unstable/strange? way to do it. It works fine on my site, without any errors, but bad coding can do that sometimes. Here is the code:


function Skin_title($page_title) {
$this->page_title = $page_title;

     print '<table cellpadding="3" cellspacing="0" border="0" width="100%" bgcolor="efa02c">
<tr><td valign="top">' . $page_title . '</td></tr></table>';



<?php include("pagetitles.php"; ?>
<?php skin_title('Songs and First Lines'); ?>


Suzanne Suzanne
Posts: 4

Starting with OOP is pretty good, most people start with procedural!

It doesn't appear to have any security flaws, however you can always tuck your included files in a non-web-browsable directory (pagetitles.php) to make sure?

I would note that with your markup, however, it would be much more portable to have it as '<h1>' . $page_title . '</h1>' instead, and use CSS to style it. (or with <div> tags -- the table element isn't being used well in your example).

Maia Maia
Posts: 4

Thanks. I have some more ideas now and hope to impliment your suggestions sometime soon. I've been spending way too much time over at Quirksmode investigating css & div options. Sad how things some ways tables were rather nice.

Jdenny Jdenny
Posts: 65

Over-complicated or what!

The simple answer is simmilar to using SSI (server-side-includes), but obviously with much more potential, (you can do stuff like you origional solution - but only do so when the complexity is needed to add value to your work).

PHP Includes:
in all of you pages put
$page_title = "....";

in header.php put

<table cellpadding="3" cellspacing="0" border="0" width="100%" bgcolor="efa02c">
<tr><td valign="top"><?php echo $page_title; ?></td></tr></table>

You must login to reply