session_start()
在Firefox中工作正常,但在chrome中不起作用。我还在文件的顶部写了session_start()
,但仍然在谷歌浏览器中不起作用。
如果设置了会话,我在代码中添加了一个检查,然后将向用户显示一个页面。在chrome中,它总是转到else语句。在Firefox中它完美无缺。
<?php
session_start();
include("connection.php");
if (isset($_SESSION['adminid'])) {
?>
<!DOCTYPE html>
<html>
<head>
<title>SezaPharma AdminPanel</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="shortcut icon" type="image/png" href="images/favicon.png"/>
</head>
<body>
<div class="dashboard">
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')" id="defaultOpen">All Products</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Add New Product</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Setting</button>
<a href="logout.php" ><button class="tablinks" onclick="openCity(event, 'Tokyo')" >Logout</button></a>
</div>
<div id="London" class="tabcontent" style="overflow:auto">
<div class="site_wrapper" >
<div class="clearfix margin_top10"></div>
<div class="works01" >
<div class="container" >
<div id="grid-container" class="cbp-l-grid-fullWidth" style="overflow:visible;">
<?php
$select_post=mysqli_query($conn,"select * from products ORDER BY PID desc") or die(mysqli_error());
while($post=mysqli_fetch_array($select_post))
{
?>
<div class="cbp-item <?php echo $post['PTYPE'];?>">
<div class="cbp-caption">
<div class="cbp-caption-defaultWrap">
<img style="width:100%; height:200px;" src="UploadedImage/<?php echo $post['PIMAGELOC'];?>" alt="">
</div>
<div class="cbp-caption-activeWrap">
<div class="cbp-l-caption-alignCenter">
<div class="cbp-l-caption-body">
<h3><?php echo $post['PNAME'];?></h3>
<br />
<a href="delete_product.php?PID=<?php echo $post['PID']; ?>" class="cbp-l-caption-buttonLeft" data-title="Looking Publishing <br>reasonable always">Delete</a>
</div>
</div>
</div>
</div>
</div><!-- end item -->
<?php
}
?>
</div>
</div>
</div><!-- end works section -->
<!-- ######### JS FILES ######### -->
<!-- get jQuery used for the theme -->
<script type="text/javascript" src="js/universal/jquery.js"></script>
<script src="js/style-switcher/styleselector.js"></script>
<script src="js/animations/js/animations.min.js" type="text/javascript"></script>
<script src="js/mainmenu/bootstrap.min.js"></script>
<script src="js/mainmenu/customeUI.js"></script>
<script src="js/scrolltotop/totop.js" type="text/javascript"></script>
<script type="text/javascript" src="js/mainmenu/sticky.js"></script>
<script type="text/javascript" src="js/mainmenu/modernizr.custom.75180.js"></script>
<script type="text/javascript" src="js/cubeportfolio/jquery.cubeportfolio.min.js"></script>
<script type="text/javascript" src="js/cubeportfolio/main31.js"></script>
</body>
</html>
<?php } else{ echo " You mus Loggedin to acces this page"; } ?>
答案 0 :(得分:0)
问题不在于浏览器,因为在Web服务器出现问题时它们也会受到影响。检查您是否在Google Chrome中禁用了Cookie
如果您在自己的计算机上运行代码,请确保本地服务器处于联机模式;有时Mozilla Firefox在这种情况下很灵活。
您的代码出了问题:您的PHP条件中有</body>
和</html>
编辑
<?php
session_start();
include("connection.php");
if (isset($_SESSION['adminid'])) {
?>
<!DOCTYPE html>
<html>
<head>
<title>SezaPharma AdminPanel</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="shortcut icon" type="image/png" href="images/favicon.png"/>
</head>
<body>
<div class="dashboard">
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')" id="defaultOpen">All Products</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Add New Product</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Setting</button>
<a href="logout.php" ><button class="tablinks" onclick="openCity(event, 'Tokyo')" >Logout</button></a>
</div>
<div id="London" class="tabcontent" style="overflow:auto">
<div class="site_wrapper" >
<div class="clearfix margin_top10"></div>
<div class="works01" >
<div class="container" >
<div id="grid-container" class="cbp-l-grid-fullWidth" style="overflow:visible;">
<?php
$select_post=mysqli_query($conn,"select * from products ORDER BY PID desc") or die(mysqli_error());
while($post=mysqli_fetch_array($select_post))
{
?>
<div class="cbp-item <?php echo $post['PTYPE'];?>">
<div class="cbp-caption">
<div class="cbp-caption-defaultWrap">
<img style="width:100%; height:200px;" src="UploadedImage/<?php echo $post['PIMAGELOC'];?>" alt="">
</div>
<div class="cbp-caption-activeWrap">
<div class="cbp-l-caption-alignCenter">
<div class="cbp-l-caption-body">
<h3><?php echo $post['PNAME'];?></h3>
<br />
<a href="delete_product.php?PID=<?php echo $post['PID']; ?>" class="cbp-l-caption-buttonLeft" data-title="Looking Publishing <br>reasonable always">Delete</a>
</div>
</div>
</div>
</div>
</div><!-- end item -->
<?php
}
?>
</div>
</div>
</div><!-- end works section -->
<!-- ######### JS FILES ######### -->
<!-- get jQuery used for the theme -->
<script type="text/javascript" src="js/universal/jquery.js"></script>
<script src="js/style-switcher/styleselector.js"></script>
<script src="js/animations/js/animations.min.js" type="text/javascript">
</script>
<script src="js/mainmenu/bootstrap.min.js"></script>
<script src="js/mainmenu/customeUI.js"></script>
<script src="js/scrolltotop/totop.js" type="text/javascript"></script>
<script type="text/javascript" src="js/mainmenu/sticky.js"></script>
<script type="text/javascript" src="js/mainmenu/modernizr.custom.75180.js"></script>
<script type="text/javascript" src="js/cubeportfolio/jquery.cubeportfolio.min.js"></script>
<script type="text/javascript" src="js/cubeportfolio/main31.js"></script>
</body>
</html>
<?php } else{ echo " You mus Loggedin to acces this page"; } ?>