2015-04-22 61 views
0

我在php中实现注销功能。当我点击注销链接时,会话被销毁(使用unset($ _ SESSION ['user'])和session_destroy())。之后,页面被重定向到登录屏幕。我之前在php中作为一个独立的应用程序尝试过,它工作正常。但是当我在我的实际代码中实现它时,只有一半正在工作,即会话被破坏,但后退按钮显示用户配置文件页面。点击后退按钮,用户资料页面打开php?

userprofile.php

<?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"> &nbsp;Status </i>&nbsp;&nbsp; 
<i class="fa fa-image" style="color:black">&nbsp;Add Photo</i>&nbsp;&nbsp; 
<i class="fa fa-file-photo-o" style="color:black">&nbsp 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>&nbsp; 
<i class="fa fa-map-marker" style="color:black">&nbsp Location</i>&nbsp; 
<i class="fa fa-smile-o" style="color:black">&nbsp; 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 
     } 
?> 
+0

你需要某种形式的检查增加每个页面(或框架)确保用户在访问页面时登录。 – Frank

+0

$ _SESSION ['CurrentUser'] =“”缺少一个额外的=,它应该看起来像$ _SESSION ['CurrentUser'] ==“”,否则你只需使用exit();为它的良好做法赋值 – Epodax

+0

。标题重定向后 – user1844933

回答

0

你如何破坏你的代码的会议?例如,如果您正在使用其他文件(即logoff.php),请确保包含session_start();在销毁会话之前。

例如:

<?php 
session_start(); 
session_unset(); 
session_destroy(); 
unset($_SESSION); 
?> 

而且,你的代码有第2行中的错误:

$_SESSION['CurrentUser']="" 

应该是:

$_SESSION['CurrentUser']=="" 
相关问题