Page 1 of 1

Session handling problems

Posted: Wed Oct 13, 2004 9:06 am
by umcookeg
Hi

I am back working on my site and I am still having problems storing and using session data. I keep getting this error message

Fatal error: Unknown(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition <b>survey</b> of the object you are trying to operate on was loaded _before_ the session was started in /srv/www/htdocs/Survey/processTrans.php on line 50

All my

Code: Select all

session_start
statements are at the top of all my pages involved. I have looked at my php.ini file and it looks ok.

Note:

<b>survey</b> of the object you are trying to operate on was loaded _before_ the session was started

I thought that

Code: Select all

session_start
was supposed to be at the top of the page before all your code. So my Survey.php page which, of course, contains my class definition is included after the session statement.

Has anyone seen the above error before? Thanks in advance

Dave

Posted: Wed Oct 13, 2004 9:13 am
by kettle_drum
There is an unknown function somewhere. Show us your code.

re:sesson handling

Posted: Wed Oct 13, 2004 9:40 am
by umcookeg
twigletmac | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Here is the code for processTrans.php

Code: Select all

<?php
	
	global $testSite;
	include_once($testSite . 'globals.php');
	include_once($testSite . 'SiteURLs.php');
	require_once $testSite . 'HTML/IT.php';
	require_once $testSite . 'SUtility.php';
	require_once 'User.php';
	require_once 'buildTransitionPage.php';
	require_once 'buildLogin.php';
	require_once 'Survey.php';          <--------- Survey.php class file
	
	session_start();   <------ just changed this, this used to be at top of page
	session_cache_limiter('private, must-revalidate');

	$try = $_SESSION['cookie'];
	if( $try != "" )
	{

	foreach( $HTTP_POST_VARS as $key=>$value )
	{
		
		if($key == "currQ")
		{
			$nextQues = $HTTP_POST_VARS[$key];
			 
		}//end if
		else if( $key == "random" )
		{
			$random = $HTTP_POST_VARS[$key];
		}//end else if
		else if( $key == "message" )
		{
			$message = $HTTP_POST_VARS[$key];
		}//end else if
		else if( $key == "company" )
		{
			$company = $HTTP_POST_VARS[$key];
			
		}//end else if					
	
		
	}//end foreach
	$suv = $_SESSION['surv'];             <----- This is the object I am trying to use.
	print"suv: $suv<BR>";
	if( $suv != "" )
	{
		print"Survey object is set in the session variable suv<BR>";
		$userQuestionNumber = $suv->surveyID;
		print"The usrs current question number will be: $userQuestionNumber<BR>";
		$user = $suv->getUser(); <--- This is where the error occurs
		
		$suv->qDisplay($nextQues,$message,$company);
	}//end if
	else
	{
		print"Survey object is NOT set in the session variable suv<BR>";
		$message = "You do not have cookies enabled. Survey object doesn't exist.<BR>";
		$message = $message."This survey requires that cookies be enabled.<BR>";
		$message = $message."Please follow the instructions below to enable cookies for your browser.<BR>";
		buildLogin($message);
	}//end else.
	}//end outer if
	else
	{
		$message = "You do not have cookies enabled.<BR>";
		$message = $message."This survey requires that cookies be enabled.<BR>";
		$message = $message."Please follow the instructions below to enable cookies for your browser.<BR>";
		buildLogin($message);
	}//end else


?>
Here is the code.

session handling

Posted: Wed Oct 13, 2004 9:45 am
by umcookeg
Hi
Here is how it works the user at the index.php page types in their user name and password then they are validated ( this validation is where the Survey object is instantiated and stored as a session variable ) then the system calls the build_TransitionPage.php page to display the welcome screen to the user then when the user clicks on next to begin the Survey the processTrans.php page is called and that is when I get the error message.
This site has been going through testing for a while and has worked very well up untill the Professors that I have built the thing for told me that the companies they want to survey do not want to allow cookies on their users browsers. I then started to try to figure out how I could possibly do URL re-writing but learned that php sessions don't really store cookies on the users machines anyway and that URL (in my case) won't work because I don't use html links I call php functions instead when moving the user through the survey and calling different pages.
I am stumped anyway hope alllllllll this info helps thanks for the quick reply.

Dave

(solved) session handling problems

Posted: Wed Oct 13, 2004 9:58 am
by umcookeg
Hi

The session start statments I cut into the beginning of each function that the system was calling on each page. And everything is working fine now.

So instead of putting the session start statement at the top of each page since I am calling functions and not linking from page to page via html I thought that I would put the session start statement at the beginning of the function. BINGO.

Dave