会话变量设置不正确

时间:2014-10-14 13:59:16

标签: php session session-variables

我正在尝试将会话变量从页面设置为另一个。它正在我的本地主机上工作,但后来我将它上传到我的服务器,现在它失败了。我做了一些基本的bug测试,它会在特定点打印,我在代码中标记了它们。这是我正在使用的代码的代码

// PAGE 1

session_start();
if(isset($_REQUEST['id'])){

    $_SESSION['id'] = $_REQUEST['id'];
    //prints here just fine then fails after
    header('location: app.php');

}elseif($_POST){

    if(isset($_SESSION['error'])){
        unset($_SESSION['error']);
    }

    $questions = array();

    for($i = 1; $i <= 11; $i++){
        $questions['q'.$i] = $_POST['q'.$i];
    }

    $check = "";
    foreach($questions as $key => $val){
        $check .= $val;
    }
    $metreq = strcmp($check, "1111-1-1-1-11-1-1");

    if(!$metreq){
        $_SESSION['questionaire'] = $questions;
        header("location: app.php");
    }else{
        header('location: nq.php');
    }
}   

///第2页

<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
session_start();
require_once('inc/state_list_options.php');
if(isset($_SESSION['questionaire']) || isset($_SESSION['id'])){
    $id = $first_name = $middle_name = $last_name = $suffix = $address = $city = $state = $zip = $phone_area = $phone_exch =
    $phone_num = $phone2_area = $phone2_exch = $phone2_num = $email_address = $birth_month = $birth_day = $birth_year =
    $job = $referred = "";
    $selected = "selected";
    $questions = array();
    //here we will generate a session id that is the code passed from the link clicked by the user
    $conn = mysql_connect('host', 'user', 'password');
    mysql_select_db('db', $conn);
    if($conn){
        if(isset($_SESSION['id'])){
            $id = $_SESSION['id'];
            $q = "SELECT * FROM eagle.pre_application WHERE id = '$id'";    

            $r = mysql_query($q, $conn);
            $row = mysql_fetch_assoc($r);

            $first_name = $row['first_name'];
            $middle_name = $row['middle_name'];
            $last_name = $row['last_name'];
            $suffix = $row['suffix'];
            $address = $row['address'];
            $city = $row['city'];
            $state = $row['state'];
            $zip = $row['zip'];
            $phone_area = $row['phone_area'];
            $phone_exch = $row['phone_exch'];
            $phone_num = $row['phone_num'];
            $phone2_area = $row['phone2_area'];
            $phone2_exch = $row['phone2_exch'];
            $phone2_num = $row['phone2_num'];
            $email_address = $row['email_address'];
            $birth_month = $row['birth_month'];
            $birth_day = $row['birth_day'];
            $birth_year = $row['birth_year'];
            $questions['q1'] = $row['q1'];
            $questions['q2'] = $row['q2'];
            $questions['q3'] = $row['q3'];
            $questions['q4'] = $row['q4'];
            $questions['q5'] = $row['q5'];
            $questions['q6'] = $row['q6'];
            $questions['q7'] = $row['q7'];
            $questions['q8'] = $row['q8'];
            $questions['q9'] = $row['q9'];
            $questions['q10'] = $row['q10'];
            $questions['q11'] = $row['q11'];
            $_SESSION['questionaire'] = $questions;
        }
        $q2 = "SELECT job_posting.id, job_posting.title, location.city, location.state 
        FROM eagle.job_posting
        LEFT JOIN eagle.location
        ON job_posting.location__Id = location.id";
        $j = mysql_query($q2, $conn);
        ?>
           <!-- job application goes ehre -->
        <?  
    }else{
        $_SESSION['error'] = "Please fill out the questionaire before completing the applicationn.";
        header('location: index.php');
        exit;
    }
}else{
    echo "There is an error";
}
?>

我不能100%确定从现在开始要去哪里。我当时认为这是标题造成和问题,但这种情况从未出现过这种情况我感到困惑。请让我知道你对此的看法。如果您需要其他代码或更多示例,请告诉我,我可以为您提供。提前感谢所有来帮助的人!

EDITS / DEVELOPMENTS /更新版本

上午9:07:在chrome上使用开发人员的工具,在提交到第2页时,它现在收到500服务器错误

9:16 AM删除了require_once中发现的错误(&#39;&#39;);路径中有错误。现在它只是自动进入第2页的重定向,即使通过地址栏在标题中手动传递变量。我还是难过。代码已更新以反映更改

0 个答案:

没有答案