Code: Select all
<?php
session_start();
require_once "image.dat.php";
require_once "image.map.php";
?>
<html>
<head>
<title>Image</title>
</head>
<body>
<img border="0" src="image.php" usemap="#imagemap">
<?php echo imagemap(); ?>
</body>
</html>But there are a couple of problems. The generated usemap contains links back to the above code, which pass parameters to image.dat.php where they are retrieved with a few $_GET[]s. To further optimize the data construction routines it's desirable to reuse a large portion of the data at this point, which are theoretically contained in $_SESSION['data']. However, when I use the same assignment technique used in image.php and image.map.php ($data = $_SESSION['data']) the code in image.dat.php is somehow executed multiple times resulting in a distorted image and poor performance otherwise. Strangely, if I replace occurrences like $data[THIS][THAT][ETC] with $_SESSION['data'][THIS][THAT][ETC] in image.dat.php everything seems to work fine.
This behavior leads me to believe I don't know what I'm doing. I'm not anxious to replace all occurrences of $data just because it works. Why does it work in image.php and image.map.php but not in image.dat.php? All code and view pages begin with session_start(). What is the server doing in terms of the load and execution sequence that I'm missing?
Additionally, it would be nice to optimize the page load of the above code by allocating the image dimensions with height and width attributes, otherwise there is a highly visible hiccup as the browser double refreshes the screen after computing the height and width. Again, I can't retrieve the $_SESSION variable via assignment without affecting the image as above. However, if I use a non-parented reference e.g. $data[HEIGHT] = $_SESSION['data'][HEIGHT] as opposed to $data = $_SESSION['data'] and then using $data[HEIGHT] the problem goes away. But even when using the $_SESSION['data'][HEIGHT] approach FF does not fully refresh the image. Both IE and Safari show better performance.
Maybe I'm using an invalid approach to begin with. I would appreciate hearing your comments if you have any ideas or questions.