dongpa5277 2017-12-14 11:02
浏览 41
已采纳

登录系统:会话开始的问题

I have a login system which checks for the correct login details like below :

    <?php
    @session_start();
    require_once "connection.php";
    $Username=$_POST['uname'];
    $Password=$_POST['pass'];

    $encrypt_password=md5($Password);
    //echo $encrypt_password; 

    $Username=stripslashes($Username);
    $Password=stripslashes($Password);
    $Username = mysql_real_escape_string($Username);
    $Password = mysql_real_escape_string($Password);

    $sql="SELECT * FROM loginlist WHERE username='$Username' and password='$encrypt_password'";
    $query=mysql_query($sql) or die(mysql_error());
    $Count=mysql_num_rows($query);
    if($Count == 1)
    {
        session_register(myusername);
        session_register(mypassword);
        $_SESSION['uname']=$Username;
        $_SESSION['pass']=$Password;

        header("location:controlpanel.php");
    }
    else
    {
        echo 'wrong user name or password';
    }
?>

if the login details are correct it will transfer to the controlpanel.php, I have the below code at the start of controlpanel.php

    @session_start();
    if(!isset($_SESSION['uname']))
       echo"<script>window.location='thisisthesystem.php';</script>";
    else

but every time I try to login (with correct login details) it throws me back to the login page. Please let me know what's going on wrong there :

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • douzuizhuo0587 2017-12-14 11:16
    关注

    You should lookup at the isset more.

    ISSET checks the variable to see if it has been set, in other words, it checks to see if the variable is any value except NULL or not assigned a value. ISSET returns TRUE if the variable exists and has a value other than NULL. That means variables assigned a " ", 0, "0", or FALSE are set, and therefore are TRUE for ISSET.

    if ( isset($Variable)){
      //this will be true if $Variable will have some value
    }else {
    //this is false if $Variable will be empty
    }
    

    So remove ' ! ' From if as I have said in comment section

    See more about Isset

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看