我在一个php图表包中工作。我从发送到answer.php页面的form.html开始。answer.php创建会话。然后,所需的test.php页面将选取该会话,但所需的graph.php页面不会。我无法将我的数据从表单传输到图表。所需的phplot.php是图形引擎,在会话线程中不需要。
我已经花了五天的时间研究和测试,但没有任何运气。我已经多次更换了代码。我希望有很好的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>';
?>谢谢,
加里
发布于 2017-04-01 04:29:19
在每个页面你要使用"$_SESSION“的第一件事你需要通过"session_start()”启动会话如果会话启动在代码中不存在你不能从$ _SESSION变量中获取数据,我建议使用$_POST变量你的php会话没有满并且不会引起问题。
使用这个:(通过$_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希望我能帮上忙
干杯
发布于 2017-04-01 23:54:41
嗨,路易斯·费尔南多·索萨·卡马戈,
在路易斯·费尔南多·索萨·卡马戈的帮助下,我做到了!
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);
?>谢谢路易斯·费尔南多·索萨·卡马戈
加里
https://stackoverflow.com/questions/43146310
复制相似问题