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 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?