Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 重定向时不回显会话_Php_Html_Sql - Fatal编程技术网

Php 重定向时不回显会话

Php 重定向时不回显会话,php,html,sql,Php,Html,Sql,在我的主页上,我有以下代码: <?php $required = array('post_question'); // making sure post field is not empty $error = false; foreach($required as $field) { if (empty($_POST[$field])) { $error = true; } } if(isset($_POST['post_question'])){ if ($error) { echo "

在我的主页上,我有以下代码:

<?php
$required = array('post_question');
// making sure post field is not empty
$error = false;
foreach($required as $field) {
if (empty($_POST[$field])) {
$error = true;
}
}
if(isset($_POST['post_question'])){
if ($error) {
echo "please type your question and submit!";
} else {
session_start();
$ps = $_POST['post_question'];
$_SESSION['postquestion']=$_GET['ps'];
header("Location: http://localhost/voidportals/success.php");
}     
}
?>

我在同一页上有相应的表格

<form action="" method="post">
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3 col-sm-offset-3">
<input type="text" placeholder="ask your question!"  class="assin assin-success assin-autosize" name="post_question">
<input type="submit">
</div>
</form> 

然后,正如您看到的,我的php代码运行并重定向到另一个php页面

<?php
$pss = "";
session_start();
if(isset($_SESSION['ps'])){
$pss = $_SESSION['ps'];
}   
echo $_SESSION['pss'];
?>

现在,回音不回音pss。我以前从未使用过session,也不知道出了什么问题。有人能帮我吗

我得到以下错误:
未定义索引pss错误。

您从未在代码中设置会话['ps']。 如下面代码所示进行设置,并且始终
exit()标题('location:')
之后执行code>,否则脚本执行不会终止。仅设置另一个标头不足以重定向

<?php
$required = array('post_question');
// making sure post field is not empty
$error = false;
foreach ($required as $field) {
    if (empty($_POST[$field])) {
        $error = true;
    }
}
if (isset($_POST['post_question'])) {
    if ($error) {
        echo "please type your question and submit!";
    } else {
        session_start();
        $ps = $_POST['post_question'];
        $_SESSION['ps'] = $ps;
        header("Location: http://localhost/voidportals/success.php");
        exit();
    }
}
?>

第二页:

<?php
$pss = "";
session_start();
if(isset($_SESSION['ps'])){
    $pss = $_SESSION['ps'];
}
echo $pss;
?>

您从未在代码中设置
$\u会话['ps']
。 如下面代码所示进行设置,并且始终
exit()标题('location:')
之后执行code>,否则脚本执行不会终止。仅设置另一个标头不足以重定向

<?php
$required = array('post_question');
// making sure post field is not empty
$error = false;
foreach ($required as $field) {
    if (empty($_POST[$field])) {
        $error = true;
    }
}
if (isset($_POST['post_question'])) {
    if ($error) {
        echo "please type your question and submit!";
    } else {
        session_start();
        $ps = $_POST['post_question'];
        $_SESSION['ps'] = $ps;
        header("Location: http://localhost/voidportals/success.php");
        exit();
    }
}
?>

第二页:

<?php
$pss = "";
session_start();
if(isset($_SESSION['ps'])){
    $pss = $_SESSION['ps'];
}
echo $pss;
?>



您是否在第一页上开始了
会话
?主页上的会话_start()丢失?抱歉。添加了会话开始。仍然不起作用。使用会话edit编辑代码行,这将用于wan访问吗?否则,您可能需要重新考虑重定向url。它正处于测试阶段,因此从现在起使用wamp即可实现。您是否在第一页上执行了
session\u start
?主页上的session\u start()丢失?抱歉。添加了会话开始。仍然不起作用。使用会话edit编辑代码行,这将用于wan访问吗?否则,您可能需要重新考虑重定向url。它处于测试阶段,因此目前使用wamp实现。html中的
ps
命名元素是什么?$ps=$\u POST['POST\u question']$_会话['postquestion']=$_GET['ps'];我不知道这是如何工作的,但我将post_问题从输入字段保存到ps作为会话,但您从未设置
$\u会话['ps']
?$\u会话['ps']=$\u获取['ps'];这有什么不同吗?html中的
ps
命名元素是什么?$ps=$\u POST['POST\u question']$_会话['postquestion']=$_GET['ps'];我不知道这是如何工作的,但我将post_问题从输入字段保存到ps作为会话,但您从未设置
$\u会话['ps']
?$\u会话['ps']=$\u获取['ps'];这有什么不同吗?