my HTML header - any feedback?

D

dittonamed

I will be building a "template" from this to be included in each page
of a PHP/JS/HTML project i'm starting soon, but I'm curious what other
connoisseurs might think of my layout. Hmm like throwing the GET/POST
processing between the <head> and <body> tags is a new idea, but it
seems logical. Any caveats or anything watch out for?

Any thoughts?

Cheers!




<?php
# Header Output, cookies, session, auth, etc...
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<?php
# includes for the head section
?>
<!-- other head items, meta tags, javascript, css, title -->
</head>

<?php
# processing php, ajax requests, POSTS, GETS, etc
?>

<body>
<?php
# output php/html/etc
?>
</body>
</html>
 
D

David Dorward

dittonamed said:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

(a) That triggers quirks mode rendering in some browsers
(b) 4.0 was replaced by 4.01 fairly quickly
(c) We're long past the transitional period, browsers have caught up now

i.e. use HTML 4.01 Strict

No lang attribute?
<?php
# processing php, ajax requests, POSTS, GETS, etc
?>

It seems odd to do this part way through the document. Especially so for
responses to Ajax requests (which usually won't be HTML documents).
 
M

Michael Fesser

..oO(David Dorward)
It seems odd to do this part way through the document.
ACK

Especially so for
responses to Ajax requests (which usually won't be HTML documents).

It may also cause problems if the processing of form data should require
a following redirect, which happens quite regularly in my own scripts to
avoid a repost of the form data just by reloading the page in the
browser. Every processing should be done before the first line of
output, not somewhere in the middle of it.

Micha
 
M

Mike Placentra II

I will be building a "template" from this to be included in each page
of a PHP/JS/HTML project i'm starting soon, but I'm curious what other
connoisseurs might think of my layout. Hmm like throwing the GET/POST
processing between the <head> and <body> tags is a new idea, but it
seems logical. Any caveats or anything watch out for?

Any thoughts?

Cheers!

There's no advantage to processing in the middle of the output. It
makes more sense not to separate your code into header and processing
blocks. All processing should usually be done before any output so you
don't end up with spaghetti code.

You may want to look at the Model-View-Controller (Model2 for web)
design pattern, and maybe check out some frameworks such as Code
Igniter or Zend Framework. It should then be clear that processing is
best done before any output.

Good luck,
-Michael Placentra II | PHP5 ZCE
 
J

Jerry Stuckle

Mike said:
There's no advantage to processing in the middle of the output. It
makes more sense not to separate your code into header and processing
blocks. All processing should usually be done before any output so you
don't end up with spaghetti code.

Sure there is. It keeps the processing right where the results are
being used. No more spaghetti code than doing everything up front.
You may want to look at the Model-View-Controller (Model2 for web)
design pattern, and maybe check out some frameworks such as Code
Igniter or Zend Framework. It should then be clear that processing is
best done before any output.

Not necessarily. And the MVC pattern doesn't necessarily require
processing be done all at the beginning.
Good luck,
-Michael Placentra II | PHP5 ZCE


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
(e-mail address removed)
==================
 
T

Toby A Inkster

Mike said:
There's no advantage to processing in the middle of the output. It makes
more sense not to separate your code into header and processing blocks.
All processing should usually be done before any output so you don't end
up with spaghetti code.

My general technique nowadays is not to distinguish so much between
processing and output. My PHP builds up a large object, representing the
page, and at the end, I just run:

print $page->toHTML;

or somesuch. Only one print statement for the entire PHP script, and no
HTML outside the <?php ... ?> block.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 17 days, 23:00.]

Gnocchi all'Amatriciana al Forno
http://tobyinkster.co.uk/blog/2008/01/15/gnocchi-allamatriciana/
 
A

AGw. (Usenet)

I will be building a "template" from this to be included in each page
of a PHP/JS/HTML project i'm starting soon, but I'm curious what other
connoisseurs might think of my layout. [...]

<?php
# Header Output, cookies, session, auth, etc...
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

As others have pointed out, this should be 4.01 Strict for new web
pages; you're also missing the URL. Here's what you should have
instead:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
TR/html4/strict.dtd">
(wrap as appropriate)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top