Why the browser can affect the php session?
===






please see my page: http://iphoneuknow.com/test/controller/selectEvent.php

at 1st page, click submit to 2nd page

2nd page will receive value from post, use that value select data from DB, and save to session

3rd page will print the session.

the problem is, different browser or version at 3rd page may successfully or not successfully print the session

please see the code first.

all code also can be downloaded here: http://iphoneuknow.com/test/test.7z



three page are:


1st: selectEvent.php

	<?php
	session_start();
	session_destroy(); //ensure session is empty for each test
	?>
	<form method="post" action="eventDetail.php">
	<input type="text" name="eventID" value="1">
	<input type="submit"/>
	</form>



2nd: eventDetail.php

	<?php
	session_start();
	require_once('../db.php');
	require_once('../model/MemberModel.php');
	require_once('../model/EventModel.php');

	$member = new MemberModel();
	$event = new EventModel();
	$selectedEvent=$event->getEventByID($_POST['eventID']);
	$eventAllMember=$member->getMemberByEventID($_POST['eventID']);
	$_SESSION['selectedEvent']=$selectedEvent;



	for($i=0; $i<count($eventAllMember); $i++)
	{
		echo '<img src="'.$eventAllMember[$i]->image.'"/>';
	}
	?>
	<a href="register.php">next</a>

	<pre>
	<?
	print_r($selectedEvent);

	print_r($eventAllMember);
	?>
	</pre>


3rd: register.php

	<?php
	session_start();
	?>
	<pre>
	<? print_r($_SESSION['selectedEvent']); ?>
	</pre>




and two model to get data from DB



EventModel.php

	<?php
	class EventModel
	{
		public function getEventByID($id)
		{
			$sql="select * from event where id=$id";
			$result=mysql_query($sql);
			$row=mysql_fetch_assoc($result);
			$o = new stdClass;
			$o->id=$row['id'];
			$o->dataNotFromDB='not from DB';
			return $o;
		}
	}
	?>



MemberModel.php

	<?php
	class MemberModel
	{
		public function getMemberByEventID($eventID)
		{
			$sql="select * from member where id in (select member_id from event_member where event_id=$eventID)";
			$result=mysql_query($sql);
			$arr=array();
			while($row=mysql_fetch_assoc($result))
			{
				$o = new stdClass;
				$o->image=$row['image'];
				array_push($arr,$o);
			}
			return $arr;
		}
	}
	?>



------------------------------------------------------

the correct result at 3rd page is:

	stdClass Object
	(
		[id] => 1
		[dataNotFromDB] => not from DB
	)

incorrect result is:
id is no value, but another attribute of the object which not from DB is still alive

	stdClass Object
	(
		[id] => 
		[dataNotFromDB] => not from DB
	)





I have tested many browser, these can get correct result

chrome 20

ie9

ff14

but some older version or browser will get incorrect result, such as

ff 6.0.2

safari 5.1.5



I don’t understand why different browser can affect the php session at server side

I can sure this is not a cookies problem, because some session is work, some is not.

so where is the problem? client? server? or coding?



--------------------------------

any one of following change can fix the problem, but it make me confusing, because they are not related to each other




1

use get to send id from 1st page to 2nd page rather then post


2 at eventDetail.php

	//change
	$selectedEvent=$event->getEventByID($_POST['eventID']);
	$eventAllMember=$member->getMemberByEventID($_POST['eventID']);

	//to
	$_POST['eventID']=1; // assign a value to post
	//or
	$selectedEvent=$event->getEventByID(1); //or hardcode the value as parameter
	$eventAllMember=$member->getMemberByEventID(1);


3 at eventDetail.php


	//change
	echo '<img src="'.$eventAllMember[$i]->image.'"/>';
	//to
	echo $eventAllMember[$i]->image;


4 at MemberModel.php

	
	//change
	$o->image=$row['image'];
	//to
	$o->image=$row['image'].’some string’; // ensure no empty