By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,109 Members | 993 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,109 IT Pros & Developers. It's quick & easy.

my 1st use of session variables

P: n/a
I've written some code to overlay a transparent png over a jpeg, 4 4
links then allow the png to be moved, the x and y coordinates being
stored in $_SESSION.
It seems to work fine on my own local server but only intermitently
when live.
The full source with images is stored in
http://www.pherber.com/test/test.zip

Any help would be much appreciated.

index.php:
<?php session_name("pwh_test_session"); session_start(); ?>
<html><head><title>Test page</title>
<meta name="author" content="Paul Herber">
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-15">
<style type="text/css">
.mtitle {font-size:24pt; font-family:arial,helvetica,sans-serif}
.mtext {font-size:10pt; font-family:arial,helvetica,sans-serif}
</style>
</head>
<body bgcolor="#FFFFEC">
<div class=mtext align="center">

<?php
$_SESSION['x'] = 0;
$_SESSION['y'] = 0;
?>

<table border="0" align="center">
<tr><td>Starting session named <?php echo session_name();
?></td></tr>
<tr><td colspan="4" align="center"><a
href="show.php">Start</a></td>
</tr>
</table>

</div>
</body>
</html>

show.php:
<?php session_start(); ?>
<html><head><title>Test page</title>
<meta name="author" content="Paul Herber">
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-15">
<style type="text/css">
.mtitle {font-size:24pt; font-family:arial,helvetica,sans-serif}
.mtext {font-size:10pt; font-family:arial,helvetica,sans-serif}
</style>
</head>
<body bgcolor="#FFFFEC">
<div class=mtext align="center">

<?php
$d = $HTTP_GET_VARS['d'];
?>

<table border="0" align="center">
<tr>
<td colspan="4" align="center"><img class=mborder2 width="500"
height="375" border="0" title="" alt=""
<?php echo "src=\"showimage.php?d=$d\">";?></td></tr>
</tr>
<tr>
<td width="25%" align="center"><a href="show.php?d=u">Up</a></td>
<td width="25%" align="center"><a
href="show.php?d=d">Down</a></td>
<td width="25%" align="center"><a
href="show.php?d=l">Left</a></td>
<td width="25%" align="center"><a
href="show.php?d=r">Right</a></td>
</tr>
<tr><td colspan="4" align="center">
<?php echo 'x = ' . $_SESSION["x"] . ' y = ' . $_SESSION["y"];
?>
</td></tr>
<tr><td colspan="4" align="center">
<?php
if (($_SESSION["x"]==346) and ($_SESSION["y"]==180) ):
echo 'You have been hit for 6!';
endif;
if (($_SESSION["x"]==306) and ($_SESSION["y"]==240) ):
echo 'Batsman is out LBW';
endif;
if (($_SESSION["x"]==186) and ($_SESSION["y"]==220) ):
echo 'Bowled - middle stump!';
endif;
?>
</td></tr>
</table>

</div>
</body>
</html>

shopimage.php:
<?php
session_start();
$d = $HTTP_GET_VARS['d'];

$im1 = imagecreatefromJPEG('P6200007.jpg');
$im2 = imagecreatefromPNG('redball.png');

if ($d == 'u'): { $_SESSION["y"] = $_SESSION["y"] - 20; }
elseif ($d == 'd'): { $_SESSION["y"] = $_SESSION["y"] + 20; }
elseif ($d == 'l'): { $_SESSION["x"] = $_SESSION["x"] - 20; }
elseif ($d == 'r'): { $_SESSION["x"] = $_SESSION["x"] + 20; }
else: {
$_SESSION["x"] = imagesx($im1) - imagesx($im2)/2;
$_SESSION["y"] = imagesy($im1)/2 - imagesy($im2)/2; }
endif;
// check limits
if ($_SESSION['y'] < 0): $_SESSION['y'] = 0;
endif;
if ($_SESSION['y'] > imagesy($im1)-imagesy($im2)): $_SESSION['y'] =
imagesy($im1)-imagesy($im2);
endif;
if ($_SESSION['x'] < 0): $_SESSION['x'] = 0;
endif;
if ($_SESSION['x'] > imagesx($im1)-imagesx($im2)): $_SESSION['x'] =
imagesx($im1)-imagesx($im2);
endif;
imagecopy($im1, $im2, $_SESSION["x"], $_SESSION["y"], 0, 0,
imagesx($im2), imagesy($im2));

$mime="image/jpeg";
header("Content-Type: $mime");
header("Content-Disposition: filename=overlayedimage.jpg");

imageJPEG($im1);
imageDestroy($im1);
imageDestroy($im2);
?>
--
Regards, Paul Herber, Paul Herber Systems Ltd. http://www.pherber.com/
SanDriLa - SDL/MSC application for Visio
email address is spam-trapped - s/*@/paul@/
Jul 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.