如果rowcount恰好为0,我想保存sessionStorage项目,我知道我不应该在标题之前回显任何内容,因此,请告诉我在标题之前设置sessionStorage的最佳方法是什么条件。只有js和php,不想使用jquery。提前谢谢!
<?php
$admin_table = "admin_table";
$show_all_admins = "SELECT * FROM $admin_table";
$show_all_admins_query = mysqli_query($conn, $show_all_admins);
$rowcount = mysqli_num_rows($show_all_admins_query);
if($rowcount == 0 ){
mysqli_close($conn);
echo'<script>sessionStorage.setItem("admin_sessn", "admins");</script>';
header('Location: http://localhost/littlesidegym.php');
exit();
}
?>
答案 0 :(得分:0)
一种选择是在javascript中处理重定向而不是PHP
<script>
sessionStorage.setItem("admin_sessn", "admins");
window.location = 'http://localhost/littlesidegym.php';
</script>