Click here to Skip to main content
15,881,248 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
GeneralRe: QT Pin
Iranian MM24-Nov-11 0:07
Iranian MM24-Nov-11 0:07 
GeneralRe: QT Pin
Richard MacCutchan24-Nov-11 0:40
mveRichard MacCutchan24-Nov-11 0:40 
GeneralRe: QT Pin
Iranian MM24-Nov-11 3:32
Iranian MM24-Nov-11 3:32 
GeneralRe: QT Pin
Richard MacCutchan24-Nov-11 5:36
mveRichard MacCutchan24-Nov-11 5:36 
AnswerRe: QT Pin
mikemar26-Nov-11 14:15
mikemar26-Nov-11 14:15 
GeneralRe: QT Pin
Iranian MM27-Nov-11 1:39
Iranian MM27-Nov-11 1:39 
GeneralRe: QT Pin
mikemar27-Nov-11 5:42
mikemar27-Nov-11 5:42 
GeneralRe: QT Pin
Iranian MM27-Nov-11 18:00
Iranian MM27-Nov-11 18:00 
GeneralRe: QT Pin
mikemar27-Nov-11 19:11
mikemar27-Nov-11 19:11 
GeneralRe: QT Pin
Albert Holguin28-Nov-11 8:18
professionalAlbert Holguin28-Nov-11 8:18 
GeneralRe: QT Pin
Albert Holguin28-Nov-11 8:19
professionalAlbert Holguin28-Nov-11 8:19 
GeneralRe: QT Pin
Albert Holguin28-Nov-11 8:27
professionalAlbert Holguin28-Nov-11 8:27 
Questionmaster page of include? Pin
Jassim Rahma19-Nov-11 4:48
Jassim Rahma19-Nov-11 4:48 
AnswerRe: master page of include? Pin
Satheesh154621-Nov-11 17:15
Satheesh154621-Nov-11 17:15 
AnswerRe: master page of include? Pin
cjoki23-Nov-11 12:08
cjoki23-Nov-11 12:08 
I use includes with function calls.


file structure might look like...
/index.php
/main_inc.php
/template/header.php
/template/menu.php
/template/footer.php


index.php and most other pages would look like this...
<?php
include(main_inc.php);
//*************************** index content start

//*************************** index content end
footer($pg_name); // attrib is set in main_inc.php and can be called here
?>



main_inc.php. $pg_name is obtained automatically
<?php
// if using a session start here, otherwise ignore this and the next line.
session_start()

$pg_name = substr($_SERVER['SCRIPT_NAME'],strrpos($_SERVER['SCRIPT_NAME'],"/")+1);
include('/template/header.php');
include('/template/footer.php'
?>


The header file....
<?php
/*
   this should be local to the header file, if it does not work add the '/template/' to the start of menu.php
*/
include('menu.php');
pg_init($pg_name);
pg_header(pg_name);

function pg_init($pg_name)
{
   // set session or global variables related to this page...
}

function pg_header($pg_name)
{
   // if using global init vars reference them here, should not matter for sessions
   echo "<html>";
   echo "<head>";
   echo "<title>".$pg_title."</title>"; // from an init var
   // add script or even style data as needed. Because you are passing the page name you can load just what you want for the page.
   echo "<script>...</script>";
   echo "<style>...</style>";
   echo "</head>";
   echo "<body>"; // you can also include body onload/onunload events to the body tag based on page..if your into that sort of thing ;)
   pg_menu($pg_name);  // remember the include for the menu.php above...well here you call the function inside of it.
}
?>



The menu.pgp page
<?php
function pg_menu($pg_name)
{
   // logic to display menu and highlight current page.
}
?>



The footer.php page
<?php
// close up the page and if need be add special code for specific pages...like javascript added to the bottom of a page.
function pg_footer($pg_name)
{
echo "</body>";
echo "</html>";
}
?>



This whole thing could be done without using function calls, but I like the parameter passing and with more thought I can add some security, input checking, page name validation, and more and more...

this is a fairly simple template but very flexible
Chris J
www.redash.org

Questionfix the top panel Pin
Jassim Rahma19-Nov-11 4:35
Jassim Rahma19-Nov-11 4:35 
AnswerRe: fix the top panel Pin
Graham Breach19-Nov-11 5:34
Graham Breach19-Nov-11 5:34 
AnswerRe: fix the top panel Pin
Satheesh154621-Nov-11 17:20
Satheesh154621-Nov-11 17:20 
QuestionLearn Red Hat for Beginners Pin
Devdattahack1018-Nov-11 7:01
Devdattahack1018-Nov-11 7:01 
AnswerRe: Learn Red Hat for Beginners Pin
Albert Holguin18-Nov-11 7:37
professionalAlbert Holguin18-Nov-11 7:37 
AnswerRe: Learn Red Hat for Beginners Pin
Lensman218-Nov-11 8:49
Lensman218-Nov-11 8:49 
GeneralRe: Learn Red Hat for Beginners Pin
Albert Holguin18-Nov-11 9:24
professionalAlbert Holguin18-Nov-11 9:24 
Questiondetermine page title Pin
Jassim Rahma17-Nov-11 5:24
Jassim Rahma17-Nov-11 5:24 
AnswerRe: determine page title Pin
Smithers-Jones18-Nov-11 2:27
Smithers-Jones18-Nov-11 2:27 
GeneralRe: determine page title Pin
Jassim Rahma19-Nov-11 4:26
Jassim Rahma19-Nov-11 4:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.