Page 1 of 1
case/switch problem after upgrading?
Posted: Mon Nov 18, 2002 7:21 am
by bobc
I was running an older version of php on a server, version 4.0.1 pl2 and just upgraded it to 4.2.3, ever since the upgrade, when I try to access a page using a case/switch statement, it doesn't load the proper page, it just defaults to whatever is declared as default in the script. Any help is greatly appreciated...
Thanks in advance,
Bob
Posted: Mon Nov 18, 2002 7:23 am
by twigletmac
Without seeing any code I think it's likely to be an issue regarding register_globals:
viewtopic.php?t=511
Have a read of the above which should explain what I mean. If you then need help upgrading your script to work properly with register_globals off (which is now the default for new installations of PHP) post some code and we'll be glad to help.
Mac
Posted: Mon Nov 18, 2002 7:36 am
by bobc
Thanks for the speedy reply, I just read the above thread but should I set register globals to "on" or would you recommend re-writing the following code? How could I re-write the following:
<?
{
require("header.html");
}
?>
<?
switch($id) {
case "history":
require("history.php");
break;
case "links":
require("links.php");
break;
case "team":
require("team.php");
break;
case "news":
require("news.php");
break;
case "image_gallery":
require("image_gallery.php");
break;
case "off_the_press":
require("off_the_press.php");
break;
default:
require("index_body.php");
break;
}
?>
<?
{
require("footer.html");
}
?>
Thanks again in advance,
BobC
Posted: Mon Nov 18, 2002 7:44 am
by twigletmac
I wouldn't recommend turning register_globals on (all my reasoning is contained within the thread I linked you to) but you may have to as a temporary measure whilst you get your scripts up to spec with the new version of PHP.
As for the code you posted, assuming that $id is coming from the URL, I would recommend changing your code to something like the following:
Code: Select all
<?
/* This sets the $id value so that you can use it later on */
$id = (!empty($_GETї'id'])) ? $_GETї'id'] : '';
require 'header.html';
switch($id) {
case 'history':
require 'history.php';
break;
case 'links':
require 'links.php';
break;
case 'team':
require 'team.php';
break;
case 'news':
require 'news.php';
break;
case 'image_gallery':
require 'image_gallery.php';
break;
case 'off_the_press':
require 'off_the_press.php';
break;
default:
require 'index_body.php';
break;
}
require 'footer.html';
?>
Mac