I have two pages, one assigns all the variables and the second page generates a image using the session variables, well about half of the variables are working and I verified that the session array contains all the information is there, the image php script is linked via <img> tag and loads fine but just half of the session variables are not loading with it. Here is the code. The $SESSION['dfname2'] varible never loads on the image script but it does work fine on this page.
<?php
// start the session
session_start();
require("../config.php");
$result = mysql_query("SELECT * FROM memorial WHERE id=$id",$db);
$myrow = mysql_fetch_array($result);
//Generates a random number so the browser is forced to refresh the image
srand((double)microtime()*1000000);
$picture = rand(0,100);
//Sets the graphic.php to paid mode.
$_SESSION['spreview'] = "false";
$_SESSION['dbio'] = $myrow["bio"];
$_SESSION['ddob2'] = $myrow["dob"];
$_SESSION['ddod2'] = $myrow["dod"];
$_SESSION['ddob'] = $myrow["dob2"];
$_SESSION['ddod'] = $myrow["dod2"];
$_SESSION['dfname'] = $myrow["fname"];
$_SESSION['dlname'] = $myrow["lname"];
$_SESSION['dfname2'] = $myrow["fname2"];
$_SESSION['dlname2'] = $myrow["lname2"];
$_SESSION['dmempicid'] = $myrow["mempicid"];
$_SESSION['ddual'] = $myrow["dual"];
$_SESSION['dpackage'] = $myrow["package"];
$tempname = $_SESSION['dfname'] . " " . $_SESSION['dlname'];
$tempname2 = $_SESSION['dfname2'] . " " . $_SESSION['dlname2'];
<table width="310" border="0">
<tr>
<td width="71"><? print_r($_SESSION) ?></td>
<td width="223"><img src="../graphic.php?ran=<?php echo $picture; ?>"></td>
The image script
<?php
// start the session
if(!session_id()){
session_start();
}
$mempicid = $_SESSION['dmempicid'];
$strname = $_SESSION['dfname'] . " " . $_SESSION['dlname'];
$strdate = $_SESSION['ddob'] . " - " . $_SESSION['ddod'];
$strname2 = $_SESSION['dfname2'] . " " . $_SESSION['dlname2'];
$strdate2 = $_SESSION['ddob2'] . " - " . $_SESSION['ddod2'];
//Connect to the database and grab the necessary information for the memorial pictures
$db = mysql_connect("XXXXX", "XXXX", "XXXX");
mysql_select_db("XXXX",$db);
$result = mysql_query("SELECT * FROM memorialpictures WHERE id=$mempicid",$db);
$myrow = mysql_fetch_array($result);
$mempic = $myrow["mempic"];
$dual = $myrow["dual"];
$tcolor = $myrow["textcolor"];
$tsize = $myrow["textsize"];
$dsize = $myrow["datesize"];
$talign = $myrow["textalign"];
$namel = $myrow["nameleft"];
$namer = $myrow["nameright"];
$namet = $myrow["nametop"];
$nameb = $myrow["namebottom"];
$datel = $myrow["dateleft"];
$dater = $myrow["dateright"];
$datet = $myrow["datetop"];
$dateb = $myrow["datebottom"];
$namel2 = $myrow["nameleft2"];
$namer2 = $myrow["nameright2"];
$namet2 = $myrow["nametop2"];
$nameb2 = $myrow["namebottom2"];
$datel2 = $myrow["dateleft2"];
$dater2 = $myrow["dateright2"];
$datet2 = $myrow["datetop2"];
$dateb2 = $myrow["datebottom2"];
$warmemorial= $myrow["warmemorial"];
//Changes the text aligntment to a variable
if ($talign == "ALIGN_LEFT") {
$talign = 0;
}elseif ($talign == "ALIGN_CENTER") {
$talign = 1;
}elseif ($talign == "ALIGN_RIGHT") {
$talign = 2;
}elseif ($talign == "VALIGN_TOP") {
$talign = 0;
}elseif ($talign == "VALIGN_MIDDLE") {
$talign = 1;
}elseif ($talign == "VALIGN_BOTTOM") {
$talign = 2;
}
//Function for drawing the text and aligning it
function imagestringbox(&$image, $font, $left, $top, $right, $bottom, $align, $valign, $leading, $text, $color) {
// Get size of box
$height = $bottom - $top;
$width = $right - $left;
// Break the text into lines, and into an array
$lines = wordwrap($text, floor($width / imagefontwidth($font)), "\n", true);
$lines = explode("\n", $lines);
// Other important numbers
$line_height = imagefontheight($font) + $leading;
$line_count = floor($height / $line_height);
$line_count = ($line_count > count($lines)) ? (count($lines)) : ($line_count);
// Loop through lines
for ($i = 0; $i < $line_count; $i++) {
// Vertical Align
switch ($valign) {
case VALIGN_TOP: // Top
$y = $top + ($i * $line_height);
break;
case VALIGN_MIDDLE: // Middle
$y = $top + (($height - ($line_count * $line_height)) / 2) + ($i * $line_height);
break;
case VALIGN_BOTTOM: // Bottom
$y = ($top + $height) - ($line_count * $line_height) + ($i * $line_height);
break;
default:
return false;
}
// Horizontal Align
$line_width = strlen($lines[$i]) * imagefontwidth($font);
switch ($align) {
case ALIGN_LEFT: // Left
$x = $left;
break;
case ALIGN_CENTER: // Center
$x = $left + (($width - $line_width) / 2);
break;
case ALIGN_RIGHT: // Right
$x = $left + ($width - $line_width);
break;
default:
return false;
}
// Draw
imagestring($image, $font, $x, $y, $lines[$i], $color);
}
return $image;
}
//Displays the correct memorial
if ($warmemorial == 'yes'){
$fmempic = "memorial/war/" . $mempic;
}elseif($warmemorial == 'no'){
$fmempic = "memorial/" . $mempic;
}
// Create the memorial image
$im = imagecreatefromjpeg($fmempic);
// Colors
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$grey = imagecolorallocate($im, 200, 200, 200);
if ($tcolor == "white") {
$tcolor = $white;
}else{
$tcolor = $black;
}
// Use it!
imagestringbox($im, $tsize, $namel, $namet, $namer, $nameb, $talign, VALIGN_TOP, 2, $strname, $tcolor);
imagestringbox($im, $dsize, $datel, $datet, $dater, $dateb, $talign, VALIGN_TOP, 2, $strdate, $tcolor);
imagestringbox($im, $tsize, $namel2, $namet2, $namer2, $nameb2, $talign, VALIGN_TOP, 2, $strname2, $tcolor);
imagestringbox($im, $dsize, $datel2, $datet2, $dater2, $dateb2, $talign, VALIGN_TOP, 2, $strdate2, $tcolor);
// Output
header("Content-type: image/png");
ImagePNG($im);
ImageDestroy($im);
?>