Variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gangboy
Forum Newbie
Posts: 14
Joined: Tue Jan 06, 2004 11:58 am
Location: Constanţa, România

Variables

Post 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";
?>
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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
?>
User avatar
gangboy
Forum Newbie
Posts: 14
Joined: Tue Jan 06, 2004 11:58 am
Location: Constanţa, România

Post by gangboy »

That does it! Thanks a lot!
Post Reply