Jump to content

Recommended Posts

Hey everyone, I'm new to php and am currently running php5 with a mysql. The program all runs except for one major issue, the session variable. The following is my session header:

 

<?php

session_start();

require "systemClasses.php";

if (!isset($_SESSION["basePage"]))

{

$_SESSION["basePage"] = new SemesterHandler ();

}

?>

 

and for the rest of the program I just use $_SESSION["basePage"] to access my object. The program is set up in two files right now, one is index.php where you start and it reads out to a semesters.php. The object works and I have tested it the issue is the session variable. The error I'm getting is this:

 

PHP Fatal error:  main() [<a href='function.main'>function.main</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "SemesterHandler" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition  in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\UniversitySchedulerPHP\semesters.php on line 22

Link to comment
https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/
Share on other sites

Soo heres the code...

 

index.php - All that really matters is that this is where the session starts and the object is created. It ajaxes information from semesters.php when the drop down list (called "school") is changed.

<?php

session_start();

require "systemClasses.php";

if (!isset($_SESSION["basePage"]))
{
$_SESSION["basePage"] = new SemesterHandler ();
}

?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link rel="shortcut icon" href="images/favicon.gif" type="image/gif"/>
<title>University Scheduler</title>
<script language="JavaScript" type="text/javascript" src="./javascript/ss.js"></script>
<script language="JavaScript" type="text/javascript" src="./javascript/appoints.js"></script>
<script language="JavaScript" type="text/javascript" src="./javascript/classes.js"></script>
<script language="JavaScript" type="text/javascript" src="./javascript/scheds.js"></script>
<?php
	echo "<link rel=\"StyleSheet\" href=\"./styles/".$_SESSION["basePage"]->getSchool().".css\" type=\"text/css\" />";
?>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<center>
<table width="1000" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td class="ss" height="42" width="1000" colspan="3"></td>
</tr>
<tr>
	<td class="left" width="15"></td>
	<td width="970">
	<center>
		<select id="school" onchange="submitSchool();">
		<?php 
			$temp = $_SESSION["basePage"]->getSchools();
			for ($x=0;$x<count($temp);$x++)
			{
				echo "<option value=\"".$temp[$x]."\"";
				if (strcasecmp($temp[$x], $_SESSION["basePage"]->getSchool())==0)
				{
					echo " selected=\"selected\"";
				}
				echo ">".$temp[$x]."</option>\n";
			}
			unset($temp);
		?>
		</select>
		<select id="semester" onchange="submitSemester();">
		<?php
			$temp = $_SESSION["basePage"]->getSemesters();
			for ($x=0;$x<count($temp);$x++)
			{
				echo "<option value=\"".$temp[$x]."\"";
				if (strcasecmp($temp[$x], $_SESSION["basePage"]->getSemester())==0)
				{
					echo " selected=\"selected\"";
				}
				echo ">".$temp[$x]."</option>\n";
			}
		?>
		</select>
	</center>
	</td>
	<td class="right" width="15"></td>
</tr>
<tr>
	<td class="bottom" height="42" width="1000" colspan="3"></td>
</tr>
<tr>
	<td class="appoints" height="42" width="1000" colspan="3"></td>
</tr>
<tr>
	<td class="left" width="15"></td>
	<td width="970">
		<div id="appoints">
<?php
	if (count($_SESSION["basePage"]->getAppoints())!=0)
	{
	echo "<center>\n";
	echo "<table>\n";
	echo "<tr>\n";
	echo "<th class=\"table_space\"></th>\n";
	echo "<th class=\"table_head\">Name</th>\n";
	echo "<th class=\"table_head\">Start Time</th>\n";
	echo "<th class=\"table_head\">End Time</th>\n";
	echo "<th class=\"table_head\">Days</th>\n";
	echo "</tr>\n";

	for ($y=0;$y<count($_SESSION["basePage"]->getAppoints());$y++)
	{
		$appoint = $_SESSION["basePage"]->getAppoints();
		$appoint = $appoint[$y];
		echo "<tr>\n";

		echo "<td class=\"table_cell\"><input type=\"checkbox\" "."name=\"checks".$y."\" "."id=\"checks".$y."\"/></td>\n";

		echo "<td class=\"table_cell\"><input type=\"text\" name=\"appointName".$y."\" size=\"20\" maxlength=\"20\"";
		//if (isset($appoint->getName()))
		{
			echo " value=\"".$appoint->getName()."\"";
		}
		echo "></td>\n";

		echo "<td class=\"table_cell\"><select name=\"startTimeHour".$y."\">\n";
		$timeHour = $appoint->getStartTime()/60;
		$timeMin = $appoint->getStartTime()%60;
		$isAM = true;
		if ($timeHour>12)
		{
			$timeHour-=12;
			$isAM = false;
		}
		for ($z=1;$z<=12;$z++)
		{
			echo "<option value=\"".$z."\"";
			if ($timeHour==($z))
			{
				echo " selected=\"selected\"";
			}
			echo ">".$z."</option>\n";
		}
		echo "</select>\n";
		echo ":";
		echo "<select name=\"startTimeMin".$y."\">";
		for ($z=0;$z<=59;$z++)
		{
			echo "<option value=\"".$z."\"";
			if ($timeMin==($z))
			{
				echo " selected=\"selected\"";
			}
			if ($z<10)
			{
				echo ">0".$z."</option>\n";
			}
			else
			{
				echo ">".$z."</option>\n";
			}
		}
		echo "</select>\n";
		echo "<select name=\"startTimeDay".$y."\">";
		if (!isAM)
		{
			echo "<option value=\"am\">am</option>\n";
			echo "<option value=\"pm\" selected=\"selected\">pm</option>\n";
		}
		else
		{
			echo "<option value=\"am\" selected=\"selected\">am</option>\n";
			echo "<option value=\"pm\">pm</option>\n";
		}
		echo "</select></td>\n";

		$timeHour = $appoint->getEndTime()/60;
		$timeMin = $appoint->getEndTime()%60;
		$isAM = true;
		if ($timeHour>12)
		{
			$timeHour-=12;
			$isAM = false;
		}

		echo "<td class=\"table_cell\"><select name=\"endHour".$y."\">";
		for ($z=1;$z<=12;$z++)
		{
			echo "<option value=\"".$z."\"";
			if ($timeHour==($z))
			{
				echo " selected=\"selected\"";
			}
			echo ">".$z."</option>";
		}
		echo "</select>";
		echo ":";

		echo "<select name=\"endMin".$y."\">";
		for ($z=0;$z<=59;$z++)
		{
			echo "<option value=\"".$z."\"";
			if (timeMin==(z))
			{
				echo " selected=\"selected\"";
			}
			if (z<10)
			{
				echo ">0".$z."</option>";
			}
			else
			{
				echo ">".$z."</option>";
			}
		}
		echo "</select>";

		echo "<select name=\"endTimeDay".$y."\">";
		if (!$isAM)
		{
			echo "<option value=\"am\">am</option>";
			echo "<option value=\"pm\" selected=\"selected\">pm</option>";
		}
		else
		{
			echo "<option value=\"am\" selected=\"selected\">am</option>";
			echo "<option value=\"pm\">pm</option>";
		}
		echo "</select></td>";

		echo "<td class=\"table_cell\">";
		echo "<table>";
		echo "<tr>";
		echo "<td class=\"table_cell\">Monday</td>";
		echo "<td class=\"table_cell\">Tuesday</td>";
		echo "<td class=\"table_cell\">Wednesday</td>";
		echo "<td class=\"table_cell\">Thursday</td>";
		echo "<td class=\"table_cell\">Friday</td>";
		echo "</tr>";
		echo "<td class=\"table_cell\"><input type=\"checkbox\" name=\"appointDays".$y."\" value=\"M\"";
		if ((isset($_GET["days".$x]))&&(!(strripos($_GET["days".$x], "M")===false)))
		{
			echo "checked=\"checked\"";
		}
		echo "></td>";
		echo "<td class=\"table_cell\"><input type=\"checkbox\" name=\"appointDays".$y."\" value=\"T\"";
		if ((isset($_GET["days".$x]))&&(!(strripos($_GET["days".$x], "T")===false)))
		{
			echo "checked=\"checked\"";
		}
		echo "></td>";
		echo "<td class=\"table_cell\"><input type=\"checkbox\" name=\"appointDays".$y."\" value=\"W\"";
		if ((isset($_GET["days".$x]))&&(!(strripos($_GET["days".$x], "W")===false)))
		{
			echo "checked=\"checked\"";
		}
		echo "></td>";
		echo "<td class=\"table_cell\"><input type=\"checkbox\" name=\"appointDays".$y."\" value=\"H\"";
		if ((isset($_GET["days".$x]))&&(!(strripos($_GET["days".$x], "H")===false)))
		{
			echo "checked=\"checked\"";
		}
		echo "></td>";
		echo "<td class=\"table_cell\"><input type=\"checkbox\" name=\"appointDays".$y."\" value=\"F\"";
		if ((isset($_GET["days".$x]))&&(!(strripos($_GET["days".$x], "F")===false)))
		{
			echo "checked=\"checked\"";
		}
		echo "></td>";
		echo "<tr>";
		echo "</tr>";
		echo "</table>";
		echo "</td>";

		echo "</tr>";
	}
	echo "</table>";
	echo "</center>";
	}
	 ?>
		</div>
		<center>
		<input type="button" class="flat" name="addClass" onclick="submitAddAppoint();" value="Add an Appointment" />
		<input type="button" class="flat" name="remClass" onclick="submitRemAppoint();" value="Remove checked Appointment" />
		</center>
	</td>
	<td class="right" width="15"></td>
</tr>
<tr>
	<td class="bottom" height="42" width="1000" colspan="3"></td>
</tr>
<tr>
	<td class="classes" height="42" width="1000" colspan="3"></td>
</tr>
<tr>
	<td class="left" width="15"></td>
	<td width="970">
		<div id="classes"></div>
		<center>
		<input type="button" class="flat" name="addClass" onclick="submitAddClass();" value="Add a Class" />
		<input type="button" class="flat" name="remClass" onclick="submitRemClass();" value="Remove checked classes" />
		<input type="button" class="flat" name="subClass" onclick="submitAppoints(true);" value="Submit and create schedules" />
		</center>
	</td>
	<td class="right" width="15"></td>
</tr>
<tr>
	<td class="bottom" height="42" width="1000" colspan="3"></td>
</tr>
<tr>
	<td class="scheds" height="42" width="1000" colspan="3"></td>
</tr>
<tr>
	<td class="left" width="15"></td>
	<td width="970">
		<center>
		<div id="schedulesNum"></div>
		<div id="schedule"></div>
		</center>
	</td>
	<td class="right" width="15"></td>
</tr>
<tr>
	<td class="bottom" height="42" width="1000" colspan="3"></td>
</tr>
</table>
</center>
</body>
</html>

semesters.php - just reads from the object (which is why i need to be able to use it).
<?php

session_start();

require "systemClasses.php";

if (!isset($_SESSION["basePage"]))
{
$_SESSION["basePage"] = new SemesterHandler();
}

?>
<?php
if (isset($_GET["school"])!=0)
{
	$_SESSION["basePage"]->setSchool($_GET["school"]);
	//adds appointments
	$_SESSION["basePage"]->removeAllAppoints();
	for ($x=0;isset($_GET["startHour"+$x]);$x++)
	{
		$name = "";
		if (isset($_GET["appointName"+$x]))
		{
			$name = $_GET["appointName"+$x];
		}
		$days = $_GET["days"+$x];
		$startTime = intval($_GET["startHour"+$x])*60;
		if ($_GET["startTimeDay"+$x].equals("pm"))
		{
			$startTime += 720;
		}
		$startTime += intval($_GET["startMin"+$x]);
		$endTime = intval($_GET["endHour"+$x])*60;
		if ($_GET["endTimeDay"+$x].equals("pm"))
		{
			$endTime += 720;
		}
		$endTime += intval($_GET["endMin"+$x]);
		$_SESSION["basePage"]->addAppoint(
			$name,
			$days,
			$startTime,
			$endTime);
	}
}
if (isset($_GET["semester"]))
{
	$_SESSION["basePage"]->setSemester($_GET["semester"]);
}
?>

Nope runs perfectly when the session variable is replaced with a random variable. It has something to do with getting information from the session variable i think because when you create the session the program runs fine but when you try to get the variable from the session it sorta dies and i get that error

So im guessing my header should look more like this in all my php files?

 

<?php

 

include "systemClasses.php";

 

session_start();

 

if (!isset($_SESSION["basePage"]))

{

$_SESSION["basePage"] = new SemesterHandler ();

}

 

?>

 

If this is true then it still doesnt work...

As of PHP 4.3.3, calling session_start() while the session has already been started will result in an error of level E_NOTICE. Also, the second session start will simply be ignored.

 

this is what I did....

 

if (!isset($_SESSION['sessionIsActive'])) {
session_start();
$_SESSION['sessionIsActive'] = true;
}

Thanks for helping get rid of the notification but i still have the reason for this post... this error:

 

[08-May-2007 11:06:47] PHP Fatal error:  main() [<a href='function.main'>function.main</a>]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "SemesterHandler" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition  in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\UniversitySchedulerPHP\index.php on line 22

 

I figured it out... The issue isn't with my code at all, instead it was with my php.ini. I need to turn off session.auto_start because what it does is start the session when the first <?php tag is hit. Well since i had a class i created myself, it would try to create an object that php didnt know about thus resulting in an error... makes sense when you realize the issue

 

Now how do i mark this thread as solved?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.