会话在一个页面中工作,但不是另一个
我正在使用php制图软件包。我从一个发送到answer.php页面的form.html开始。 answer.php创建SESSION。然后一个必需的test.php页面会选择会话,但所需的graph.php页面不会。我无法将我的数据从表单传输到图表。所需的phplot.php是图形引擎,在SESSION线程中不需要。会话在一个页面中工作,但不是另一个
我花了五天研究和测试没有运气。我已经多次转换编码。我希望具有丰富PHP经验的人能够轻松识别某些内容。
这三个页面的编码如下。
answer.php页:
<?php
session_unset();
session_start();
require_once 'phplot/test.php';
?>
<?php
$_POST['bs_now2'];$bs_now2 = $_POST['bs_now2'];$_SESSION['bs_now2'] = $bs_now2;
echo "<div id='graph'>";
echo "<p class='martop10 f18 b'>Graph:</p>";
echo "<img src='phplot/graph.php'>";
echo "</div>";
?>
<?php
session_destroy();
?>
graph.php页:
<?php
$Sbs_now2 == 0;
session_start();# Is this redundant? I've tried it in and out.
?>
<?php
require_once 'phplot.php';#Graph engine
$delta = 0.1;$sigma = 15;$sqrt2pi = sqrt(2*M_PI);$u = 75;
$data = array();
for ($x = 0; $x <= 150; $x++)
$data[] = array('', $x, $Sbs_now2 + $x);
unset($Sbs_now2);
?>
test.php的页面:
<?php
#I don't need the session_start() for this page
$_POST['bs_now2'];$bs_now2 = $_POST['bs_now2'];$_SESSION['bs_now2'] = $bs_now2;$Sbs_now2 = $_SESSION['bs_now2'];
echo '<b>Session BS Now: '.$Sbs_now2.'</b><br>';
?>
谢谢
加里
第一件事在每一页你将使用“$ _SESSION”,你需要通过“session_start()”开始会话,如果会话启动不在代码中,你不能从$ _SESSION变量获取数据,我建议使用$ _POST可变你的php会话不充分,不会出现问题,
使用此:(通行证throught $ _ POST)
<?php
// passing data to the post
$_POST['data'] = "Test using Post";
// Receiving the data from the post
$data = $_POST['data'];
// to test and see if it works
echo $_POST['data']; // or echo $data
希望我帮助
干杯
吕喜z费尔南多索萨卡马戈和所有,
在Luiz Fernando Sousa Camargo的帮助下,我已经掌握了!
answer.php页面有一个变化:
<?php
session_unset();
session_start();
require_once 'phplot/test1.php';
?>
<?php
$_POST['bs_now2'];$bs_now2 = $_POST['bs_now2'];$_SESSION['bs_now2'] = $bs_now2;$Sbs_now2 = $_SESSION['bs_now2'];
echo "<div id='graph'>";
echo "<p class='martop10 f18 b'>Graph:</p>";
echo "<img src='phplot/bs4c.php?bs_now2=$Sbs_now2'>";#CHANGE:
#I set bs_now2= to the session variable(as it would come from the form input). No other changes.
echo "</div>";
?>
<?php
session_destroy();
?>
graph.php页面有一个重要的变化:
<?php
$Sbs_now2 == 0;
session_start();
$_GET['bs_now2'];$bs_now2 = $_GET['bs_now2'];$_SESSION['bs_now2'] = $bs_now2;$Sbs_now2 = $_SESSION['bs_now2'];#CHANGE
#Use GET to acquire the session variable
#Remove End php and Start php Marks(not important)
require_once 'phplot.php';
$data = array();
for ($x = 0; $x <= 150; $x++)
$data[] = array('', $x, $Sbs_now2 + $x);
unset($Sbs_now2);
?>
谢谢路易斯·费尔南多·索萨卡马乔和所有,
加里
如何评价对答案有贡献的成员?我想引用Luiz Fernando Sousa Camargo的贡献。 – landt5
请在您的问题中添加更多详细信息,查看如何提供示例代码:https:// stackov erflow.com/help/mcve – dparoli
谢谢。我刚刚重新格式化了这个帖子,因为我是新手,正在学习论坛。 – landt5