case/switch problem after upgrading?

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
bobc
Forum Newbie
Posts: 2
Joined: Mon Nov 18, 2002 7:21 am

case/switch problem after upgrading?

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
bobc
Forum Newbie
Posts: 2
Joined: Mon Nov 18, 2002 7:21 am

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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

&lt;? 
/* This sets the $id value so that you can use it later on */
$id = (!empty($_GET&#1111;'id'])) ? $_GET&#1111;'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'; 
?&gt;
Mac
Post Reply