dongtuoji5396 2015-08-11 16:42
浏览 25

当我登录我的网络主页时,它无法正常工作

When I log into my networks homepage it is not working. I have connected to the database and can create new users however when I log in I am getting the else statement that shows my session is not working. (It was redirecting back to log in but for learning purposes I set it to echo).

Below is my log in code and homepage code (basic structure). I know it is not secure yet I am still getting to the security part I just need to figure out why this error is happening.

<?php require ("insert.php"); ?>
<?php
    if(isset($_POST[ 'Login' ]))
    {
    session_start();
    $email= mysqli_real_escape_string($con, $_POST ['email']);
    $pswrd= mysqli_real_escape_string($con, $_POST ['pswrd']);

    $result = $con->query(" select * from users where email='$email' AND pswrd='$pswrd' ");

    $row = $result->fetch_array(MYSQLI_BOTH);



    $_SESSION["UserID"] = $row['User_ID'];
    header ('Location: home.php');
    }
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
    <title>AMSadler login</title>
    <meta charset="utf-8">
    <meta name="description" content="description of webpage">
    <meta name="keywords" content="keywords go here">
    <meta name="author" content="Anthony">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/login.css">
    <link rel="index" href="index.php">
    <link rel="icon" href="img/favicon.png" sizes="16x16" type="image/png">
</head>
<body>

        <div class="header">
            <div id="logo">
                <a href="index.html"><img src="img/logo.png" alt="logo" title="AMSadler.com"/></a>
            </div>

            <div id="signup">
                <button type="button"><a href="signup.php">Sign up</a></button>
            </div>
        </div>

        <div id="login">
            <form method="post" action="home.php">
                <input type="text" name="email" placeholder="Email address">
                <br>
                <input type="password" name="pswrd" placeholder="Password">
                <br>
                <input id="Login" type="submit" name="Login" value="Login">
            </form>
        </div>

        <footer>
            <div id="copyright">
                <p>&copy Copyright 2015</p>
            </div>
        </footer>

</body>
</html>


<?php require ("insert.php"); 
session_start(); 
if (isset($_SESSION ["UserID"] ) ) {
}
else {
    echo "not fixed";
    // header ('Location: login.php');
}
?>



<!DOCTYPE html>
<html lang="en-US">
<head>
    <title>AMSadler</title>
    <meta charset="utf-8">
    <meta name="description" content="description of webpage">
    <meta name="keywords" content="keywords go here">
    <meta name="author" content="Anthony">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/home.css">
    <link rel="icon" href="img/favicon.png" sizes="16x16" type="image/png">
</head>
<body>

        <div class="header">

            <div id="logo">
                <a href="index.html"><img src="img/logo.png" alt="logo" title="AMSadler.com"/></a>
            </div>

            <div id="headertop">
                <div id="pagetitle">
                    <a href="home.php">HOME</a>
                </div>

                <div id="pagetitle2">
                    <a href="profile.php">PROFILE</a>
                </div>
                <div id="pagetitle3">
                    <h4>Welcome:<?php echo $_SESSION["UserID"];?>to your page</h4>
                </div>
            </div>

        </div>

            <div class="wrapper">

                <div class="leftsidebar">
                    <ul>
                        <li><a href="home.php">Social</a></li>
                        <li><a href="#">jhbjhbjhb</a></li>
                        <li><a href="#">jhbbjhb</a></li>
                        <li><a href="#">jhbbjhbj</a></li>
                        <li><a href="#">jhbhjbjhb</a></li>
                        <li><a href="#">bjhbjhb</a></li>
                        <li><a href="#">rege</a></li>
                        <li><a href="#">rgerger</a></li>
                        <li><a href="#">dfbrtbr</a></li>
                        <li><a href="#">sdvdfgbd</a></li>
                    </ul>
                </div>

                <div class="main">
                    <div id="maintop">
                        <div id="textboxwrap">
                            <textarea name="text" id="styled"rows="5" cols="80" placeholder="Write something here.">
                            </textarea> 
                        </div>

                        <div id="postbutton">
                            <input type="submit" name="post" value="Post" />
                        </div>
                    </div>

                    <div id="mainbottom1">
                        <div ="mainbottomwrap">
                            Your posts will go here.<br>Your posts will go here.<br>Your posts will go here.<br>Your posts will go here.<br>
                            Your posts will go here.<br>Your posts will go here.<br>Your posts will go here.<br>Your posts will go here.<br>
                            Your posts will go here.<br>Your posts will go here.<br>Your posts will go here.<br>Your posts will go here.<br>
                            Your posts will go here.<br>Your posts will go here.<br>

                        </div>
                    </div>
                </div>

                <div class="rightsidebar">
                    <div id="profilecontainer">
                        <img src="img/profile.png" alt="Upload a profile pic" title="profile pic" />
                    </div>

                    <div id="box">
                        <a href="#">fgtdhrth</a><br>
                        <a href="#">dfbrt</a><br>
                        <a href="#">gverb</a><br>
                        <a href="#">dsvfe</a><br>
                        <a href="#">egerg</a><br>
                        <a href="#">wefgeger</a><br>
                        <a href="#">rfthrtth</a><br>
                        <a href="#">gergreg</a>
                    </div>
                </div>
            </div>

</body>
</html>
  • 写回答

1条回答 默认 最新

  • douke7274 2015-08-11 16:45
    关注

    Your server-side code for logging in is never actually invoked. That code is expecting the form to POST back to that same page (the login page). But instead, it posts to the next page (the home page):

    <form method="post" action="home.php">
    

    The result is that you never set the session variable on the login page, so there's no value to be read on the home page.

    POST the form to the page which expects to handle the form:

    <form method="post" action="login.php">
    

    Also please note that storing user passwords in plain text is a famously bad idea. You're going to want to obscure those passwords with a 1-way hash. Anything else is grossly negligent to your users.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100