Development need a bit of PHP help

Discussion in 'Software' started by Atomic, 15 Sep 2010.

  1. Atomic

    Atomic Gerwaff

    Joined:
    6 May 2002
    Posts:
    9,646
    Likes Received:
    94
    I've inherited a clients website and there's some php code on the template thing, that doesn't work properly! I don't really understand it... Can any of you guy help?

    PHP:
    <?php
    if(empty($page))
    {
        
    header("Location: http://www.website.com/?page=home");


    switch (
    $page) {
    case 
    "home":
       
    $file "home.php";
       
    $title "Home";
    break;
    case 
    "doineed":
       
    $file "doineed.php";
       
    $title "Do I need an EPC?";
    break;
    case 
    "aboutepcs":
       
    $file "aboutepcs.php";
       
    $title "About EPC's";
    break;
    case 
    "newbuild":
       
    $file "newbuild.php";
       
    $title "New-Build";
    break;
    case 
    "energysavingtipsv":
       
    $file "energysavingtips.php";
       
    $title "Energy Saving Tips";
    break;
    case 
    "aboutus":
       
    $file "aboutus.php";
       
    $title "About Us";
    break;
    case 
    "test":
       
    $file "404.php";
       
    $title "Uber-Test";
    break;
    default:
       
    $file "404.php";
       
    $title "Page Not Found";
    }
    ?> 
    Then there's the navigation which is like this:
    PHP:
    <li<?php if($page == "home"){echo ' class="current"'; } ;?>><a href="?page=home">Home</a></li>
    <li<?php if($page == "doineed"){echo ' class="current"'; } ;?>><a href="?page=doineed">Do I need an EPC? </a></li>
    (etc...etc...)
    And this which I can guess links in the content which is in separate files...
    PHP:
    <div id="content">
            <?php require_once($file); ?>
    </div>
     
  2. capnPedro

    capnPedro Hacker. Maker. Engineer.

    Joined:
    11 Apr 2007
    Posts:
    4,381
    Likes Received:
    241
    I'm guessing you have that old (silly) setting in php.ini disabled (as it should be)... I can't remember the name... something like allow_setting_of_any_variable_from_GET_data register_globals*...

    Anyways, replace
    PHP:
    if(empty($page))
    {
        
    header("Location: http://www.website.com/?page=home");
    }  
    with
    PHP:
    $page = isset($_GET["page"]) ? $_GET["page"] : "home";

    *
     
    thehippoz likes this.
  3. Atomic

    Atomic Gerwaff

    Joined:
    6 May 2002
    Posts:
    9,646
    Likes Received:
    94
    Spot on! Trust their to be something like that I didn't know about!
     

Share This Page