Image Kills session in IE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Image Kills session in IE

Post by hawleyjr »

Alright check this out. I was displaying an image dynamically by doing the following:

Code: Select all

<img src="<?php echo 'getimg.php?id=abc;?>" width="100" height="100">
Works fine... However, I had to do this five times so I first created five blank img tags:

Code: Select all

<img src="" width="100" height="100">
<img src="" width="100" height="100">
<img src="" width="100" height="100">
<img src="" width="100" height="100">
<img src="" width="100" height="100">
And then inserted my PHP one img at a time:

Code: Select all

<img src="<?php echo 'getimg.php?id=abc;?>" width="100" height="100">
<img src="" width="100" height="100">
<img src="" width="100" height="100">
<img src="" width="100" height="100">
<img src="" width="100" height="100">
and then...

Code: Select all

<img src="<?php echo 'getimg.php?id=abc;?>" width="100" height="100">
<img src="<?php echo 'getimg.php?id=def;?>" width="100" height="100">
<img src="" width="100" height="100">
<img src="" width="100" height="100">
<img src="" width="100" height="100">
etc....

I was testing the image each time to make sure it worked. The images showed up in FF just fine. They also showed up in IE just fine...

However, this is where I got stumped. When I refreshed the page in IE my session died and it took me back to my login page.

After investigating I found that in IE if you insert an image with a blank src="" for whatever reason your session variables die...?

Code: Select all

//No good in IE:
<img src="" width="100" height="100">
I fixed my code and it works fine. However, I haven't heard of this happening.

Here is example code:

Code: Select all

<?php
session_start();

if(isset($_SESSION['MY_SESSION'])){
	
	echo 'Session is Set';
}else{
	echo 'Session is not set';
	//SET SESSION
	$_SESSION['MY_SESSION'] = 'Hello World';
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<img src="" width="100" height="100">
</body>
</html>
In FF after the first refresh it shows "Session is Set" and a blank image. In IE after the refresh it still shows "Session is not set"

Give it a try...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

works, as expected in IE 6.0.2900.2180 SP2 and Firefox 1.0.6 for me.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

With that said. I loaded the same page onto another server. Works fine in both IE and FF.

This has to be a server setting with IE not just IE...?

Any ideas?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

use curl to send a false (IE) user-agent to both servers asking for the headers as well as pages.. compare and contrast. :)
Post Reply