单击后退按钮,用户配置文件页面打开php?
我正在用php实现注销功能。当我单击注销链接时,会话将被销毁,使用unset$\u session['user']和session\u destroy。在此之后,页面被重定向到登录屏幕。我以前在php中作为一个独立的应用程序尝试过这个,它工作正常。但当我在实际代码中实现它时,只有一半工作正常,即会话被破坏,但后退按钮显示用户配置文件页面 userprofile.php单击后退按钮,用户配置文件页面打开php?,php,button,browser,logout,back,Php,Button,Browser,Logout,Back,我正在用php实现注销功能。当我单击注销链接时,会话将被销毁,使用unset$\u session['user']和session\u destroy。在此之后,页面被重定向到登录屏幕。我以前在php中作为一个独立的应用程序尝试过这个,它工作正常。但当我在实际代码中实现它时,只有一半工作正常,即会话被破坏,但后退按钮显示用户配置文件页面 userprofile.php <?php session_start(); if(!isset($_SESSION['CurrentUser']
<?php
session_start();
if(!isset($_SESSION['CurrentUser']) && $_SESSION['CurrentUser']="")
{
header('Location:/login.html');
}
else{
if(isset($_POST['submit']))
{
include('Config.php');
$UserId=$PostContent=$Visibilty="";
$Vi=$_POST['Vi'];
$Us=$_POST['Us'];
$Po=$_POST['Po'];
$CreateDate = date("Y/m/d");
$insert="insert into Post(Vi,Po,Us,CreateDate) values('".$Vi."','".$Po."','".$Us."','".$CreateDate."')";
$insertresult=mysql_query("$insert");
if($insertresult)
{
header('Location:/userprofile.php');
}
else
{
echo "problem inserting data";
}
}
if(isset($_SESSION['CurrentUser']))
{
$user = $_SESSION["CurrentUser"];
//echo $user;
}
include("Config.php");
$select = "select Post.*, concat(registration.Firstname,' ',registration.Lastname) as Name, about.ProfilePic from post LEFT JOIN about On Post.UserId=About.UserId inner join registration on registration.Id = post.UserId where post.UserId ='".$user."' order by post.PostId desc LIMIT 5";
$selectResult = mysql_query($select);
//echo $selectResult;
include("refrences.php");
?>
<style>
body
{
background-color:lightgrey;
}
li.hover a:hover i.hover
{
background-color:pink;
}
</style>
<body>
<?php
include("Nav.php");
?>
<div class="container" style="background-color:whitesmoke;">
<form action="" method="post" class="form-horizontal">
<div class="col-md-8 col-md-offset-3">
<i class="fa fa-share-square-o" style="color:black"> Status </i>
<i class="fa fa-image" style="color:black"> Add Photo</i>
<i class="fa fa-file-photo-o" style="color:black">  Add Album</i>
</div>
<input type="hidden" name="UserId" value=<?php echo $user;?>>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<textarea class="form-control" rows="2" name="PostContent" placeholder="What's on your mind???..."></textarea>
</div>
<div class="col-md-7 col-md-offset-3">
<div class="col-md-5">
<i class="fa fa-user-plus" style="color:black">Tag Friends</i>
<i class="fa fa-map-marker" style="color:black">  Location</i>
<i class="fa fa-smile-o" style="color:black"> Symbols</i>
</div>
<div class="col-md-2">
<label class="control-label" style="">Share with</label></div>
<div class="col-md-1">
<select class="form-control" id="select" name="Visibilty">
<option value="Friends">Friends</option>
<option value="Public">Public</option>
</select></div>
<div class="col-md-2 col-md-offset-1">
<input type="submit" value="Post" name="submit" class="btn btn-success">
</div>
</div>
</form>
<?php
if(mysql_num_rows($selectResult) > 0)
{
while($fetch = mysql_fetch_array($selectResult))
{
?>
<div class="col-md-8 col-md-offset-2 well" style="background-color:white;">
<div class="col-md-2 thumbnail">
<img src="ProfilePic\<?php echo $fetch['ProfilePic']; ?>" alt="<?php echo $fetch['ProfilePic']; ?>">
</div>
<div class="col-md-3">
<p><a href="#"><b style="color:darkred;"><?php echo $fetch['Name']; ?></b></a></p>
<span><?php echo $fetch['PostContent']; ?></span></br>
<i class="fa fa-thumbs-o-up">Like,</i>
<i class="fa fa-share">share</i>
<span><?php echo $fetch['Visibilty']; ?></span>
<span><?php echo $fetch['CreateDate']; ?></span>
</div>
</div>
<?php
}
}
else
{
?>
<div class="col-md-8 col-md-offset-2">
<div class="alert alert-warning text-center">
Nothing to share..!!
</div>
</div>
<?php
}
?>
<div class="col-md-3 col-md-offset-5">
<input type="submit" value="See More......" name="submit" class="btn btn-success">
</div>
</div>
</body>
<?php
}
?>
如何在代码中销毁会话?例如,如果您正在使用另一个文件,即logoff.php,那么请确保包含session_start;在销毁会话之前 例如:
<?php
session_start();
session_unset();
session_destroy();
unset($_SESSION);
?>
应该是:
$_SESSION['CurrentUser']==""
您需要为每个页面或框架添加某种检查,以确保用户在访问页面时已登录。$\u SESSION['CurrentUser']=缺少一个额外的=,它应该看起来像$\u SESSION['CurrentUser']==,否则您只需使用exit指定一个值它的良好做法;在头重定向之后,我注意到一些安装无法使用isset检查数组是否有密钥。在我看来,array\u key\u exists是一个更好的选择。@Epodax谢谢您,先生
$_SESSION['CurrentUser']==""