Can a session variable exist in both the php file that creates a graph and the php file that calls it?
I want to:
1. set a session variable in the php file that creates the JpGraph and then
2. access that session variable later in the php file that calls the php file that creates the JpGraph.
But its not working.
More specifically, I have 2 php files: graph_harness.php and graph.php. graph_harness.php starts a session, sets a session variable and prints "<img src='graph.php' />" to create the JpGraph. graph.php starts the session, changes the session variable, creates the graph, and completes. graph_harness.php prints out the session variable. The change made by graph.php to the session variable is not evident in the output of graph_harness.php.
graph_harness.php:
Code: Select all
<?php
session_start();
?>
<html><head><title>Graph Harness</title></head><body>
<?php
$_SESSION['MySession'] = 'initial_MySession';
print "<img src='graph.php' /><br />";
print '<p>$_SESSION["MySession"] is: '.$_SESSION['MySession']."</p>\n";
?>
</body></html>Code: Select all
<?php
session_start();
$_SESSION['MySession'] = 'new_MySession';
include ("/var/www/html/craigraph/jpgraph-2.2/src/jpgraph.php");
include ("/var/www/html/craigraph/jpgraph-2.2/src/jpgraph_bar.php");
// Unix times: Feb 1 2007, Feb 2 2007, Feb 3 2007
$x = array(1172707200, 1172793600, 1172880000);
$y = array(13, 35, 6);
$graph = new Graph(600, 300);
$graph->SetScale('textlin');
$graph->xgrid->Show();
$tickLabels = array();
for ($i = 0; $i < count($x); ++$i)
$tickLabels[] = date('M d y', $x[$i]);
$graph->xaxis->SetTickLabels($tickLabels);
$plot = new BarPlot($y);
$graph->Add($plot);
$graph->Stroke();
?>Code: Select all
...graph...
$_SESSION["MySession"] is: initial_MySessionI used session_id() to verify that both php files have the same session ID.
Is there a way to make this work?
Thanks,
Griff