我很难使用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';
?>
答案 0 :(得分:0)
你想要替换&用和:
if (isset($_SESSION['monster']) and isset($_SESSION['spol']) and isset($_SESSION['combat']) and isset($_SESSION['turns']) and isset($_SESSION['zmaga']) and isset($_SESSION['zguba']) &
isset($_SESSION['cekini']) and 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'];
}
答案 1 :(得分:0)
您应该在PHP中查看logical operators。在许多编程语言中(包括PHP)&
是'按位和'运算符(非逻辑)。由于您需要逻辑运算符,因此您需要使用&&
或and
。另外看看其他PHP操作符,只是为了熟悉它们并避免这样的问题。
此外,如果您在if / then块之外使用这些值,您应该考虑语句为false的情况,并为这些变量分配一些默认值。