$ _SESSION变量在GoDaddy上设置为null

时间:2018-06-27 12:03:10

标签: php mysqli session-variables godaddy-api

这是我在本地计算机上的XAMMP服务器上创建的基本登录脚本。在本地服务器上工作得很好。上载到我的Windows豪华去爸爸托管服务,它不再起作用。该脚本正确地提取了用户输入的用户名和密码,并正确对其进行了验证。但是,似乎$ _SESSION变量被设置为null。但是我知道它用来设置vars的数组不是null,因为它实际上是使用同一数组来验证登录凭据。当前,当您登录时,您会在url栏中获得代码中设置的成功消息,并在需要时正确获取错误,因此验证不是问题。我也仔细检查了会话确实已经开始,但是它似乎没有更新。我的标头中也有session_start()方法,该方法作为独立脚本包含在我的所有页面中,并包含在页面顶部。我曾尝试将其删除,并将登录脚本作为启动该会话的唯一代码,但没有任何区别。但是,如果我在标题本身中包含会话变量的设置,则可以正常工作。因此,以某种方式将会话变量设置为null。有什么想法吗?
Edit2:您可以访问selfscales.com来查看运行中的错误

<?php

 session_start();

if(isset($_POST['submit'])) {
include 'dbh.inc.php';
$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$pwd = mysqli_real_escape_string($conn, $_POST['pwd']);

//error handlers 
//check if inputs are empty
if(empty($uid) || empty($pwd)){
    header("Location: ../index.php?login=empty");
    exit();

} else {
    $sql = "SELECT * FROM users WHERE user_uid='$uid' OR user_email='$uid'";
    $result = mysqli_query($conn, $sql);
    $resultCheck = mysqli_num_rows($result);
    if($resultCheck < 1) {
        header("Location: ../index.php?login=error");
        exit();
    } else {
        if($row = mysqli_fetch_assoc($result)){
            //deashing the password 
            $hashedPwdCheck = password_verify($pwd, $row['user_pwd']);
            if($hashedPwdCheck == false){
            header("Location: ../index.php?login=error");
            exit();
            } elseif ($hashedPwdCheck == true) {
                //login in the user here
                $_SESSION['u_id'] = $row['user_id'];
                $_SESSION['u_first'] = $row['user_first'];
                $_SESSION['u_last'] = $row['user_last'];
                $_SESSION['u_email'] = $row['user_email'];
                $_SESSION['u_uid'] = $row['user_uid'];
                header("Location: ../index.php?login=success");
                exit();
            }
            }
    }
}


     }
  else {
   header("Location: ../index.php?login=error");
   exit();
    }

Edit1:索引页

<?php
  include_once 'header.php';
   include 'includes/ssdb.inc.php';
  ?>
     <link rel="stylesheet" href="testingPHP/stylesheets/w3.css">
    <section class="main-container">
    <div class="main-wrapper">
    <?php
    if(isset($_SESSION['u_id'])){
        echo '<h2>Weigh</h2>';
     } else{
        echo '<h2>Welcome To Selfscale!</h2>';
        echo '<h4>Selfscale is a web application that eliminates the need 
        for a scalehouse.</h4>';
        echo '<h4>Selfscale allows truck drivers to purchase a weigh 
          without the need to talk to anyone.</h4>';
        echo '<h4>Please sign in or login.</h4>';
        echo '<h4> Notice: First time users will need to register their 
        company, truck and trailer.</h4>';
        echo '<h4>Then purchase a weigh for a small fee.</h4>';
        echo '<h4>You will have the option to download your weigh ticket, 
         email it to yourself, or print it out the old fashion way.</h4>';
        include 'weighForm.php';
     }



    ?>
    <?php
     if(isset($_SESSION['u_id'])){

     }
     ?>

</div>
</section>

 <?php
 include_once 'footer.php';
 ?>

2 个答案:

答案 0 :(得分:0)

尝试在脚本顶部添加ob_start(),以解决问题。

<?php
 ob_start();
 session_start();

if(isset($_POST['submit'])) {
include 'dbh.inc.php';
$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$pwd = mysqli_real_escape_string($conn, $_POST['pwd']);

//error handlers 
//check if inputs are empty
if(empty($uid) || empty($pwd)){
    header("Location: ../index.php?login=empty");
    exit();

} else {
    $sql = "SELECT * FROM users WHERE user_uid='$uid' OR user_email='$uid'";
    $result = mysqli_query($conn, $sql);
    $resultCheck = mysqli_num_rows($result);
    if($resultCheck < 1) {
        header("Location: ../index.php?login=error");
        exit();
    } else {
        if($row = mysqli_fetch_assoc($result)){
            //deashing the password 
            $hashedPwdCheck = password_verify($pwd, $row['user_pwd']);
            if($hashedPwdCheck == false){
            header("Location: ../index.php?login=error");
            exit();
            } elseif ($hashedPwdCheck == true) {
                //login in the user here
                $_SESSION['u_id'] = $row['user_id'];
                $_SESSION['u_first'] = $row['user_first'];
                $_SESSION['u_last'] = $row['user_last'];
                $_SESSION['u_email'] = $row['user_email'];
                $_SESSION['u_uid'] = $row['user_uid'];
                header("Location: ../index.php?login=success");
                exit();
            }
            }
    }
}


     }
  else {
   header("Location: ../index.php?login=error");
   exit();
    }

希望这可以解决您的问题。 进一步了解ob_start()

引用http://php.net/manual/en/function.ob-start.php

答案 1 :(得分:0)

最后我打电话给GoDaddy支持。问题是session_start()方法的默认保存路径不是服务器中的实际目录。这是他们的问题,很快就解决了。感谢任何尝试提供帮助的人!