我很难使用 isset() 函数。究竟我如何告诉 php,只有当数据被分配给我的时候,比如说 $_SESSION['msg']; 变量,然后才激活它并使用它......到目前为止,我收到了很多通知:未定义的索引并且这段代码也没有这样做:
if (isset($_SESSION['monster']) &
isset($_SESSION['spol']) &
isset($_SESSION['combat']) &
isset($_SESSION['turns']) &
isset($_SESSION['zmaga']) &
isset($_SESSION['zguba']) &
isset($_SESSION['cekini']) &
isset($_SESSION['post']) )
{
$monster = $_SESSION['monster'];
$spol = $_SESSION['spol'];
$combat = $_SESSION['combat'];
$turns = $_SESSION['turns'];
$zmaga = $_SESSION['zmaga'];
$zguba = $_SESSION['zguba'];
$cekini = $_SESSION['cekini'];
$_POST = $_SESSION['post'];
}
数据应该从重定向的先前站点分配给它,但该站点并不总是激活,所以我需要一个替代方案。这就是我问这个的原因。
编辑完整代码:
session_start();
include 'razno.php';
include 'save.php';
include 'stats.php';
$igralec_ime = $_SESSION['username'];
$monster = prikazi_borba($igralec_ime);
$poskodbe = prikazi_stat('curhp', $igralec_ime);
if (prikazi_stat('curhp', $igralec_ime) == 0)
{
$moznost = 'Tvoje zdravje je resno ogroženo, vrni se domov!';
}
else if (isset($_SESSION['monster']) &&
isset($_SESSION['spol']) &&
isset($_SESSION['combat']) &&
isset($_SESSION['turns']) &&
isset($_SESSION['zmaga']) &&
isset($_SESSION['zguba']) &&
isset($_SESSION['cekini']) &&
isset($_SESSION['post']) )
{
$monster = $_SESSION['monster'];
$spol = $_SESSION['spol'];
$combat = $_SESSION['combat'];
$turns = $_SESSION['turns'];
$zmaga = $_SESSION['zmaga'];
$zguba = $_SESSION['zguba'];
$cekini = $_SESSION['cekini'];
$_POST = $_SESSION['post'];
}
update_save($igralec_ime, 'gozd', $monster);
include '../html/gozd.html';
?>