如果我取消注释session_start()代码,页面将不会显示在浏览器上

阿曼五世

这是包含会话代码的四个页面。当我运行sign_up.php页面时出现错误,指出该页面无法显示。因此,这些会议给我带来了一个问题。我在每个页面上都包含了会话代码,但是我相信问题出在header(location:........);任何解决方案上。

sign_up.php

<?php 

//session_start();
//if (!isset($_SESSION["user_login"])) {
//   header("Location: sign_up.php");
//} else {
//    $username = $_SESSION["user_login"];
//}


?>
<!----------------------------------------------------------------------------------------------------->



<h1> Sign Up </h1>
    <hr>

    <div class = "user_type"> 
     <form action="sign_up.php" method="POST" enctype="multipart/form-data">
                <input type="radio" value="Student" id="radioOne" name="account" checked/>
                    <label for="radioOne" class="radio" chec>Student   </label>
                <input type="radio" value="Landlord" id="radioTwo" name="account" />
                    <label for="radioTwo" class="radio">Landlord</label>
                <hr/>    

             <div class = "gender_options"> 
                <input type="radio" value="Male" id="male" name="gender" checked/>
                    <label for="male" class="radio" chec>Male</label>
                <input type="radio" value="Female" id="female" name="gender" />
                    <label for="female" class="radio">Female</label>    
            </div> 

             <input type="text" name="name" id="name" placeholder="Full Name" required/> <br/><br/>

             <input type="email" name="email" id="name" placeholder="Email" pattern="[a-z0-9._%+-][email protected]" required/> <br/><br/>

             <input type="text" name="password" id="name" placeholder="Password" required/><br/><br/>

             <input type="text" name="password2" id="name" placeholder="Retype Password" required/><br/><br/>

             By clicking Sign Up, you agree on our <a href="#">terms and condition</a>. <br/><br/>  

             <a href="#" class="button" style="margin-left: 600px; "><input type="submit" name="submit" value="Sign Up"/></a>
     </form>     
    </div>

    <hr>
<!---- log in code--->    

    <?php

    enter code here
    if (isset($_POST["user_login"]) && isset ($_POST["user_pass"])){
    // formatting field via reg replace to ensure email and password only conisists of letters and numbers preg_replace('#[^A-Za-z0-9]#i','', 
    $login_user = $_POST["user_login"];
    $login_password = $_POST["user_pass"];

    // password is encryted in DB (MD5) therefore user inputted password will not match encryted password in DB - we have to assign new var
    $decrypted_password = md5($login_password);

// Query which finds user (if valid) from DB - Achieving authentication via username and password       

$user_query = mysqli_query($connect, "SELECT * FROM users WHERE email = '$login_user' AND password = '$decrypted_password' AND closed = 'no' LIMIT 1"); 

    $check_user = mysqli_num_rows($user_query); // checking to see if there is infact a user which those credentials in the DB
        if ($check_user==1){

        while ($row = mysqli_fetch_array($user_query)){
                $id = $row['user_id'];
            }
enter code here
            // if the user credentials are correct, log the user in:
            $_SESSION["user_login"] = $login_user;
                header( "Location: profile_student.php" ); // refresh page
            exit;

                // if user row does not equal 1 ... 
            //exit; 
        } else {
            echo "<div class='wrong_login'>
                        <p> Email or password is incorrect, please try again. </p>


                     </div>";

        }
}   

    ?>


    <h1> Log In </h1> 

    <hr>

    <div class ="login_form">
                    <form action="sign_up.php" method="POST">
                        <input type="text" name="user_login" placeholder="Email"  pattern="[a-z0-9._%+-][email protected]"  required/><br/><br/>
                        <input type="text" name="user_pass" placeholder="Password" required/> <br/><br/>
                        <input type="submit" name="login_submit" value="Log In"/> 
                    </form>
                </div>

      </div>

home.php

<?php
session_start();
if (!isset($_SESSION["user_login"])) {
   header("Location: profile_student.php");
} else {
      $username = $_SESSION["user_login"];
}

include ("connect.php");

echo "Hello,";
echo"<br/> Would you like to logout? <a href = 'logout.php'>LogOut</a>";
?>

profile_student.php

这是用户登录时的页面,该页面将允许他们访问其信息等。

   <?php
    session_start();
    if (!isset($_SESSION["user_login"])) {
       header("Location: sign_up.php");
    } else {
          $username = $_SESSION["user_login"];
    }

    include ("includes/connect.php");
    ?>

logout.php

这是我网站的注销代码

<?php


session_start();
session_destroy();
unset($_SESSION);
session_write_close();

header( "Location: ../index.php" );
die;
?>    
佩杰

而不是在每个页面中执行session_start,而是创建一个common.php文件,并将此文件包括在所有必需的页面中。另外,您需要确保在启动会话之前没有空格,否则将引发标头已发送错误!

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如果我在浏览器中禁用 javascript,则内容 React.js 将不会加载

来自分类Dev

XML文档中的错误,浏览器将不会显示

来自分类Dev

DIV中的DIV将不会显示在浏览器中

来自分类Dev

node.js-推送新代码后,浏览器中显示的页面不会更改

来自分类Dev

我的Chrome浏览器不会在控制台上显示这些代码

来自分类Dev

浏览器将不显示图像

来自分类Dev

当我运行Npm Start时,React页面不会在浏览器中实时更改

来自分类Dev

如何使浏览器立即显示我的代码更改

来自分类Dev

如果我在地址栏中输入搜索字词,则Google Chrome浏览器不会显示所有结果

来自分类Dev

为什么我的浏览器在使用 webpack 代码拆分节点模块后显示空白页面?

来自分类Dev

我可以使用什么CSS代码,以使网页上的内容不会更改浏览器窗口大小的位置?

来自分类Dev

Rails上的图像未显示在我的浏览器中

来自分类Dev

如何修复具有 display: flex 属性的引导行元素,阻止我的页面在浏览器上显示

来自分类Dev

Python Selenium Webdriver:如果最小化浏览器,则不会向下滚动页面

来自分类Dev

标签不会显示在浏览器中

来自分类Dev

使用WAMP在浏览器中将PHP代码显示为注释

来自分类Dev

在浏览器中显示加载页面

来自分类Dev

如果URL正在重定向,我的浏览器如何知道我已经访问过页面?

来自分类Dev

我可以重定向到不同的路线,但如果我刷新浏览器,该路线将不起作用

来自分类Dev

如果浏览器缩放110%,则不会显示Google地图

来自分类Dev

PHP代码显示在浏览器中

来自分类Dev

我的轮播图片不会显示在滑块上。我在浏览器上收到“ GET local_image_path 404(未找到)”错误

来自分类Dev

Windows上的Web浏览器中不会显示流浪汉服务器的内容

来自分类Dev

此代码不会在浏览器中显示tom

来自分类Dev

html代码作为源显示在页面中,而不是由浏览器执行

来自分类Dev

如果代码在方法中,Canvas 将不会显示 PhotoImage 图片

来自分类Dev

在某些浏览器上显示行

来自分类Dev

在浏览器上显示PDF

来自分类Dev

PHP在浏览器上显示图像

Related 相关文章

  1. 1

    如果我在浏览器中禁用 javascript,则内容 React.js 将不会加载

  2. 2

    XML文档中的错误,浏览器将不会显示

  3. 3

    DIV中的DIV将不会显示在浏览器中

  4. 4

    node.js-推送新代码后,浏览器中显示的页面不会更改

  5. 5

    我的Chrome浏览器不会在控制台上显示这些代码

  6. 6

    浏览器将不显示图像

  7. 7

    当我运行Npm Start时,React页面不会在浏览器中实时更改

  8. 8

    如何使浏览器立即显示我的代码更改

  9. 9

    如果我在地址栏中输入搜索字词,则Google Chrome浏览器不会显示所有结果

  10. 10

    为什么我的浏览器在使用 webpack 代码拆分节点模块后显示空白页面?

  11. 11

    我可以使用什么CSS代码,以使网页上的内容不会更改浏览器窗口大小的位置?

  12. 12

    Rails上的图像未显示在我的浏览器中

  13. 13

    如何修复具有 display: flex 属性的引导行元素,阻止我的页面在浏览器上显示

  14. 14

    Python Selenium Webdriver:如果最小化浏览器,则不会向下滚动页面

  15. 15

    标签不会显示在浏览器中

  16. 16

    使用WAMP在浏览器中将PHP代码显示为注释

  17. 17

    在浏览器中显示加载页面

  18. 18

    如果URL正在重定向,我的浏览器如何知道我已经访问过页面?

  19. 19

    我可以重定向到不同的路线,但如果我刷新浏览器,该路线将不起作用

  20. 20

    如果浏览器缩放110%,则不会显示Google地图

  21. 21

    PHP代码显示在浏览器中

  22. 22

    我的轮播图片不会显示在滑块上。我在浏览器上收到“ GET local_image_path 404(未找到)”错误

  23. 23

    Windows上的Web浏览器中不会显示流浪汉服务器的内容

  24. 24

    此代码不会在浏览器中显示tom

  25. 25

    html代码作为源显示在页面中,而不是由浏览器执行

  26. 26

    如果代码在方法中,Canvas 将不会显示 PhotoImage 图片

  27. 27

    在某些浏览器上显示行

  28. 28

    在浏览器上显示PDF

  29. 29

    PHP在浏览器上显示图像

热门标签

归档