doutingyou2198 2014-07-29 08:18
浏览 59

$ _SESSION ['用户名']无效

This is panel login:

<?php include('header.php'); 
    $login=mysql_query("select * from user")or die(mysql_error());
    $row=mysql_fetch_row($login);
    $level = $row[3];

    session_start();            
    if (isset($_SESSION['username'])){
        if ($level == '1')
            {
                header('location:admin/index.php');
            }

        if ($level == '2')
            {
                header('location:member/index.php');
            }
    }

    ?>

        <body>
        <div class="row-fluid">
            <div class="span12">
        <center>
            </br>
            </br>
            <div id="container">
                <div id="header">
                    <div class="alert alert-success"><label>Login to the System</label></div>
                </div>

                <form method="post"> 
                <table>
                    <tr>
                        <td><label>User Name</label></td>
                        <td><input type="text" id="username" name="username" placeholder="username" required></td>
                    </tr>

                    <tr>
                        <td><label>Password</label></td>
                        <td><input type="password" id="password" name="password" placeholder="Password" required></td>
                    </tr>

                    <tr>
                        <td></td>
                        <td><button type="submit" id="submit" name="submit" class="btn btn-success">Login</button></td>
                    </tr>


                </table>
                </form>

                <?php
                    if (isset($_POST['submit'])){
                    $username=$_POST['username'];
                    $password=($_POST['password']);

                    $login=mysql_query("select * from user where user_name='$username' and user_password='$password'")or die(mysql_error());
                    $count=mysql_num_rows($login);

                    $row=mysql_fetch_row($login);
                    $level = $row[3];


                    if ($count > 0){

                    $_SESSION['username']=$row[1];
                        if ($level == 1)
                            {
                                header('location:admin/index.php');
                            }

                        if ($level == 2)
                            {
                                header('location:member/index.php');
                            }

                    }

                    else{ ?>
                    <!-- <script type="text/javascript">
                        alert("Error Login! Wrong Combination of Username and Password!");
                    </script> -->
                    <div class="alert alert-error">Error login! Please check your username or password</div>
                    <?php
                    }}
                    ?>




            </div>


        </center>
    </div>
    </div>
        </body>
    </html>

I logged in with the correct information but the system is not forwarded to the member's page. $_SESSION['username'] not working. I tried all the solutions I can find on the internet, none of them worked. I'm out ideas as to why this isn't working. Any help will be greatly appreciated, thank you.

I used this code: can you help me fix it ? Thank you very much

http://vinhomegroup.com/post2/feeds.zip

  • 写回答

4条回答 默认 最新

  • dongwh1992 2014-07-29 08:20
    关注

    You are destroying your session before reading the variable.

    session_start();
    session_destroy();
    session_start(); 
    

    Therefore you will not be able to access your $_SESSION variables.

    Remove the two first lines of the snippet above and this will be fine.

    评论

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)