我有一个带有几个按钮的 html 页面,我想将其带到另一个 PHP 页面,该页面将处理所有逻辑,但我在设置 session 时遇到问题。
我可能会以错误的方式解决这个问题,所以如果有人指出我正确的方向,我将不胜感激。
这是我正在使用的 HTML 页面代码:
<form action="reportPage.php">
<center><input type="submit" value="View customers"></center>
<?php
$_SESSION['customer'] = "checkCusTrains";
?>
</form>
<form action="reportPage.php" mehtod="post">
<center><input type="submit" value="View admins"></center>
<?php
$_SESSION['admins'] = "checkCusAdmin";
?>
</form>
我希望每个按钮都转到 reportUser.php 页面,但使用不同的 session ,因为我在报告页面中设置了 if/else 语句,该语句将显示与该 session 对应的信息。
我怎样才能实现这个目标?目前,两个 session 变量都已设置
最佳答案
我建议您使用查询而不是 session 来实现此目的:
<form action="reportPage.php?customer=checkCusTrains">
<center><input type="submit" value="View customers"></center>
</form>
<form action="reportPage.php?admins=checkCusAdmin" mehtod="post">
<center><input type="submit" value="View admins"></center>
</form>
在您的reportPage.php
中:
<?php
if(!empty($_GET['customer']) && $_GET['customer'] == 'checkCusTrains'){
//do something
}
if(!empty($_GET['admins']) && $_GET['admins'] == 'checkCusAdmin'){
//do something else
}
?>
关于php - PHP session 出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27240219/