我有一个旧脚本,它使用变量$action,然后使用switch语句。我的问题是在 PHP 5 中。7 我必须在使用变量之前声明变量 - 那么我该为切换的变量声明值吗?
if(isset($pwd) && ($action == "login") &&
($pwd == $admin_password))
{
$admintest = 1;
$cookie_value = base64_encode("jmkads:$pwd");
// 86400 secs is 24 hours
setcookie("jmkads",$cookie_value, time()+86400);
}
else if(isset($jmkads)) {
$cookie_value = base64_decode($jmkads);
$cookie_value = explode(":", $cookie_value);
if(($cookie_value[0] == "jmkads") &&
($cookie_value[1] == $admin_password))
{
$admintest = 1;
}
}
if(!$admintest) {
Login_Page();
exit;
}
$db = connect_to_db();
if($db == 0) {
echo "Unable to connect to database, check if the MySQL".
" server is active and the settings of ad_config.php".
" are correct.'n";
}
else {
switch($action) {
case "add_client":
Page_Header("Add Client");
add_client();
break;
case "add_client2":
Page_Header("Add Client");
insert_client_data();
break;
等等等等(有很多选择)——我只是想展示足够的脚本,所以它很清楚。
在您的情况下,该变量将被声明为字符串,因为您的大小写是匹配字符串。