-4

session_register 可以存储超过 1 个值吗?因为在我的查看产品页面中,我可能需要将 session_register 中的值输入到数据库中。

if(!isset($_SESSION['login_school']))
{
    header("location: ../enter-icas/");
}

这是登录页面。

$_SESSION['login_school'] = $myschoolcode;
header("location: ../view-products/");

这是用户登录后的产品页面。

目前上面的代码是存储学校代码,我怎样才能让会话也存储我的学校名称?

$myschoolcode = ($_POST['schoolcode']);
$mypassword = ($_POST['password']);

$sql = "SELECT school_id FROM schools_info WHERE SchoolCode = '$myschoolcode' and Password 
= '$mypassword'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$active = $row['active'];
$count = mysql_num_rows($result);

// If result matched $myschoolcode and $mypassword, table row must be 1 row
if($count == 1) {
session_register("myschoolcode");
$_SESSION['login_school'] = $myschoolcode;

header("location: ../view-products/");
}
4

1 回答 1

2

您可以将值分别存储在两个会话变量中,

$_SESSION['login_school_name'] = $login_school_value;
$_SESSION['login_school_code'] = $myschoolcode;

如果你想在两个会话变量中使用相同的 login_school,你可以选择数组,

  $_SESSION['login_school'] = array();
  $_SESSION['login_school']['name'] = $login_school_value;
  $_SESSION['login_school']['code'] = $myschoolcode;
于 2013-04-21T11:25:31.293 回答