How to standardize web pages?

The place for general PHP questions and hints for PHP on IBM i

How to standardize web pages?

Postby patr9257 on Wed Jul 29, 2015 9:04 pm

I am new to PHP. We have just installed Zend Server on our IBM i in our company. I will be using PHP to create several web pages for internal use in our company. What would be a good approach for standardizing the layout of all the web pages. I would like to have each page use a "master" page so that each page has the same layout. I would like to have a header that would include our logo, etc. and a footer of some sort and have the page contents in the body of the page. Any recommmendations? Should I be looking into PHP MVC? Would jQuery be a good approach? Most of the pages will be viewed in a desktop browser so I guess I don't really need jQueryMobile. Thanks, Pat
patr9257
 
Posts: 7
Joined: Wed Jun 24, 2015 4:31 pm

Re: How to standardize web pages?

Postby scottgcampbell on Tue Aug 04, 2015 9:14 pm

Probably the easiest would be as you said to have a header and footer that you include in each page:

Code: Select all
<?php
include_once './header.php';
?>
Body of the page goes here

<?php
include_once './footer.php';
?>


Then any changes you want to make to the "base" only has to be done in one place. Also you can do things like session management/validation and database connection in the header also so it is not duplicated in each page.
JQuery wouldn't really help with this (it is for javascript not PHP).

Hope that helps a bit

Scott
scottgcampbell
 
Posts: 187
Joined: Wed Apr 22, 2009 2:29 pm
Location: Edmonton, AB, Canada

Re: How to standardize web pages?

Postby patr9257 on Mon Aug 17, 2015 10:06 pm

Is it possible to mix PHP and HTML code in the same file? I have tried to embed a simple <?php echo 'Hello from PHP'; ?> script in an html file but the script does not execute. The surrounding html works just fine. If I try to embed html tags (a form in this case) in a php file, I get a 500 Internal Server Error. If I create a php script that uses the echo statement to echo html tags, that works fine. Any ideas? Thanks.
patr9257
 
Posts: 7
Joined: Wed Jun 24, 2015 4:31 pm

Re: How to standardize web pages?

Postby scottgcampbell on Tue Aug 18, 2015 1:42 pm

Is it possible to mix PHP and HTML code in the same file?

Yes, but the PHP has to be within start
Code: Select all
<?php
and end
Code: Select all
?>
tags (maybe the cause of your 500 error below?) and the HTML outside of the tags.

I have tried to embed a simple <?php echo 'Hello from PHP'; ?> script in an html file but the script does not execute. The surrounding html works just fine.

It would require a .php extension for the parser to recognize it and run the PHP, unless you have told it to treat .html files as PHP.

If I try to embed html tags (a form in this case) in a php file, I get a 500 Internal Server Error.

Post an example, or take a look at your php.log. Most likely there is an error in the file.

If I create a php script that uses the echo statement to echo html tags, that works fine.

Because there are no errors in the script :)

Scott
scottgcampbell
 
Posts: 187
Joined: Wed Apr 22, 2009 2:29 pm
Location: Edmonton, AB, Canada


Return to PHP Questions / Hints

Who is online

Users browsing this forum: No registered users and 1 guest

cron