dongmeng1868 2013-05-26 07:42
浏览 18

如果已登录,则在导航中显示注销,反之亦然[关闭]

When users log in, it will show logout. When users haven't logged in, echo the welcome message and show login. My code in some web pages are working. Yet, in some pages are shown both login and logout. I don't know why, please help.

<?php 


   session_start();
  if (isset($_SESSION['loginID_member']))


{

echo "Welcome, ".$_SESSION['loginID_member'];
echo "&nbsp;&nbsp;";
echo "<a href='../logout.php''>Logout</a>";

  }
   else 
{
  echo "Welcome, guest!";
echo "&nbsp;&nbsp;";
echo "<a href='member_login.php'>Login</a>";
}
?>
  • 写回答

2条回答 默认 最新

  • duandi8544 2013-05-26 07:53
    关注

    You are checking for the $_POST only. Simply replace it with $_SESSION like this:

    if(isset($_SESSION['loginID_member']) {
    [...]
    

    And session_start() should be at the top of the document.

    Beside this your script is not very secure, since everybody just needs to send a POST Request with the key 'loginID_member' in order to log in. Try to change your sessions 'setup'.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题