PHP Template help

  • Thread starter Thread starter adamsgi
  • Start date Start date
A

adamsgi

I have a website that is a php template, but is effectively a group of HTML files held together with a few php includes. What the site does is looks for the page name in an array and if the page name exists it allows the choice of page (and menu), if not, it displays the home page. The code is like this:

Code:
<table cellpadding="0" cellspacing="0" width="760" align="center">
 <tr>
  <td height="175" colspan="2">
  <?php
     include("header.php");
    ?></td>
 </tr>
 <tr>
  <td width="167" align="left" valign="top">
  <?php
  $menus=array('menu1','menu2','menu3','menu4');
   if(in_array($menu, $menus)) {
      include("$menu.php"); }
     else {
      include("menu1.php");
     } 
    ?></td>
  <td width="593" align="left" valign="top">
  <?php
                                          $pages=array('about','accbur','assist','bprices','case1','case2','case3','case4','contact','cvs','downloads','esr','fmprices','gp','hrabout','international','international_d','international_fr','international_es','international_it','international_pt','international_nl','irish','main','manage','manx','nofrills','outsource','quote1','recruitag','services','starter','temp','thanks','links');
     if(in_array($page, $pages)) {
      include("$page.php");
     } else {
      include("main.php");
     }
    ?></td>
 </tr>
 <tr>
  <td height="53" colspan="2">
  <?php
    include("footer.php");
    ?></td>
 </tr>
</table>

It has worked for 2 years but suddenly this month it has stopped working. Our hosts are using PHP 5.2.8 (it was PHP 4 when we originally put the website up) and I don't know what is wrong. Is there anyone out there that has come across this problem before?
 
Just wanted to know why you think that would be the problem? Should it be in single quotes instead of double quotes?

Like I said, it has worked for 2 years and we haven't changed anything. - it just suddenly stopped working. I'm not an expert in php (I am reasonable at HTML and used this function to stop people from doing:

/index.php?page=http://www.domain.com/eviltextfile

Has anything in PHP changed with v5 that means arrays have to be coded differently? The current method is:

/index.php?page=service&menu=menu2

Site is/was really well indexed on Google so I don't want to disappear from page 1 because of a broken website!
 
Upvote 0
I found a different example on the web and the correct format (now!) should be:

Code:
<table cellpadding="0" cellspacing="0" width="760" align="center">
 <tr>
  <td height="175" colspan="2">
  <?php
     include("header.php");
    ?></td>
 </tr>
 <tr>
  <td width="167" align="left" valign="top">
  <?php
 $menu = $_GET['menu'];
  $menus=array('menu1','menu2','menu3','menu4');
  if(in_array($menu, $menus)) {
   $menu .= '.php';
   include($menu); }
  else {
   include("menu1.php");
  }
 ?></td>
 <td width="593" align="left" valign="top">
  <?php
 $page = $_GET['page'];
                $pages=array('about','accbur','assist','bprices','case1','case2','case3','case4','contact','cvs','downloads','esr','fmprices','gp','hrabout','international','international_d','international_fr','international_es','international_it','international_pt','international_nl','irish','main','manage','manx','nofrills','outsource','quote1','recruitag','services','starter','temp','thanks','links');
  if(in_array($page,$pages)) {
   $page .= '.php';
   include($page);
  }
  else {
  include('page1.php');
  }
 ?></td>
 </tr>
 <tr>
  <td height="53" colspan="2">
  <?php
    include("footer.php");
    ?></td>
 </tr>
</table>

Just needed a few extra lines. I wish they wouldn't make changes like that that aren't backwards compatible!
 
Upvote 0
Just needed a few extra lines. I wish they wouldn't make changes like that that aren't backwards compatible!
In this case it was necessary to make sure it wasn't backwardly compatible because $HTTP_GET_VARS was a security risk. $_GET is a far better way of doing things.
 
Upvote 0

Latest Articles