かなり小さなアプリケーションのセットアップに問題があります。ちょっとした調査になります。
フォームは 2 つのページに分かれています。最初のものを送信した後、データは次のように$_SESSION
配列に保存されます。
save_items(array('my_data' => $my_data_oject));
関数save_items()
は次のようになります。
function save_items(array $array) {
foreach ($array as $name => $item) {
$_SESSION[$name] = $item;
}
}
次に、次unset($_POST)
のようにリダイレクトします。
header('Location: index.php?action=survey_part2');
exit;
私の問題は次のとおりです。リダイレクト後、以前に保存されたログインデータはまだ にありますが$_SESSION
、そうでmy_data_object
はありません。リダイレクトを回避すると、リダイレクトが開始される前に配列にmy_data_object
格納されていることがわかります。$_SESSION
したがって、 と の組み合わせはheader()
セッションexit
を部分的に破壊するようです。これがどのように起こるか知っている人はいますか?
最後に、コントローラーの一部:
<?php
error_reporting(E_ALL);
session_start();
require_once 'models/functions.php';
require_once 'models/classes.php';
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : NULL;
$view = $action;
$language = isset($_REQUEST['lang']) ? $_REQUEST['lang'] : 'de';
switch ($action) {
case 'login' :
if ((!empty($_POST['email'])) && (!empty($_POST['password']))) {
$user = new User();
$login = $user->find_user($_POST);
if (!empty($login)) {
set_message('Welcome ' . $login['Firstname'] . ' ' . $login['Lastname'] . '!');
save_items(array('user_id' => $login['CID']));
unset($_POST);
redirect("index.php?action=survey&lang=de"); //<- works fine. Login is kept, Message is kept.
} else {
set_message('Please try again.');
unset($_POST);
}
} else {
unset($_POST);
set_message('Try again.');
}
break;
/* ... shortage */
case 'survey' :
check_login(); //<- doesn't matter
if (empty($_POST)) {
/* ... shortage */
} else {
/* ... creation of my_data_object + setting one more message */
save_items(array('my_data' => $my_data_object));
unset($_POST);
save_items(array('test' => 'you see me?')); //<- index.php?action=survey_2 won't get it
//var_dump($_SESSION);
header('Location: index.php?action=survey_2&lang=de'); //<- does not work. Login is kept in $_SESSION, but not my_data
exit;
}
break;
ありがとう!
このトピックはおそらくここのトピックに似ていますが、私の$_SESSION
後は空ではありませんheader()
が、部分的に削除されています。