我想在php中显示一个JavaScript警告框并导航回主页面。这是我的代码在php中显示提醒框并向后导航
session_start();
$name= $_SESSION['name'];
$id= $_SESSION['id'];
//check if is a guest
if($name=="Guest"){
echo'<script type="text/javascript">alert(" You are not allowed to view this contnent"); </script>';
header('Location: mainPage.php');
}
//the rest of my page
使用此代码警报弹出不显示只有重定向。我也试试这个
$name= $_SESSION['name'];
$id= $_SESSION['id'];
//check if is a guest
if($name=="Guest"){
echo'<script type="text/javascript">window.alert(" You are not allowed to view this contnent");</script>';
echo'<script type="text/javascript> window.navigate("mainPage.php"); </script>';
}
//the rest of my page
现在显示弹出窗口,但重定向不起作用。