Page 1 of 1

Variables

Posted: Tue Jan 06, 2004 11:58 am
by gangboy
Hello. I am a total newbie to PHP.

Wonder how to get this right. This is a part from the index.php of my website. This page should display the same header and footer to any $html page I have defined in index.php. I know the code is (very) wrong so, please help :roll:

Code: Select all

<?php
$pagina = $_GET["pagina"];

if ($pagina=="") $pagina="Home";
if ($pagina="Home") $html="body.html";
if ($pagina="Contact") $html="contact.html";
?>
then it goes like this

Code: Select all

<?php
include "header.html";
include "$html";
include "footer.html";
?>

Posted: Tue Jan 06, 2004 12:09 pm
by JAM
Perhaps you'd prefer something similiar to this?

Code: Select all

<?php
include "header.html";          // include header

if (!empty($_GET['pagina'])) {  // check if it is set.
    $pagina = $_GET['pagina'];  // it is
} else {
    $pagina = "Home";           // its not
}

if ($pagina == "Contact") {      // show contact?
    include "contact.html";
} else {
    include "body.html";        // if not, default to this page
}

include "footer.html";          // include footer
?>

Posted: Tue Jan 06, 2004 12:26 pm
by gangboy
That does it! Thanks a lot!