PDA

View Full Version : PHP Template help


adamsgi
19th September 2009, 10:55
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:

<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','do wnloads','esr','fmprices','gp','hrabout','internat ional','international_d','international_fr','inter national_es','international_it','international_pt' ,'international_nl','irish','main','manage','manx' ,'nofrills','outsource','quote1','recruitag','serv ices','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?

Spiderden
19th September 2009, 11:10
This could be your problem

include("$page.php");

iboxsecurity
19th September 2009, 11:45
agreed at first glance that would be the problem

adamsgi
19th September 2009, 12:55
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!

adamsgi
19th September 2009, 13:23
I found a different example on the web and the correct format (now!) should be:

<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','do wnloads','esr','fmprices','gp','hrabout','internat ional','international_d','international_fr','inter national_es','international_it','international_pt' ,'international_nl','irish','main','manage','manx' ,'nofrills','outsource','quote1','recruitag','serv ices','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!

Spiderden
19th September 2009, 13:32
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.

edmondscommerce
21st September 2009, 11:04
no declaring the $page variable inside " marks is fine

I reckon they have disabled register globals - which is a good thing!