k2snowman69 Posted May 4, 2007 Share Posted May 4, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/ Share on other sites More sharing options...
zzman Posted May 4, 2007 Share Posted May 4, 2007 There is nothing wrong with your session variable. What are you trying to do with this variable. Usually you should serialize the object before storing it into a variable and unserialize before using it. post the code where you are getting that error. Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-245574 Share on other sites More sharing options...
k2snowman69 Posted May 7, 2007 Author Share Posted May 7, 2007 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"]); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-246907 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 7, 2007 Share Posted May 7, 2007 Perhaps your class has an error in it somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-246983 Share on other sites More sharing options...
k2snowman69 Posted May 7, 2007 Author Share Posted May 7, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-247400 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 8, 2007 Share Posted May 8, 2007 http://ca.php.net/function.main excerpt from someone's post... "You get this error if you have and object in your $_SESSION array and you call session_start() before you have loaded your included classes." Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-247710 Share on other sites More sharing options...
k2snowman69 Posted May 8, 2007 Author Share Posted May 8, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-247821 Share on other sites More sharing options...
neel_basu Posted May 8, 2007 Share Posted May 8, 2007 I dont understand why you guys post lots of codes. although that much code is unnecessary . Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-247839 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 8, 2007 Share Posted May 8, 2007 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; } Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-248074 Share on other sites More sharing options...
taith Posted May 8, 2007 Share Posted May 8, 2007 this is what I did.... if (!isset($_SESSION['sessionIsActive'])) { session_start(); $_SESSION['sessionIsActive'] = true; } much easier as @session_start(); therefore, always works, no complaints :-) Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-248077 Share on other sites More sharing options...
k2snowman69 Posted May 8, 2007 Author Share Posted May 8, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-248113 Share on other sites More sharing options...
JakeTheSnake3.0 Posted May 8, 2007 Share Posted May 8, 2007 Can you please show the code of both pages? Wrap each page in the [/CODE] tags. Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-248122 Share on other sites More sharing options...
k2snowman69 Posted May 8, 2007 Author Share Posted May 8, 2007 seems someone did it already... thank you whomever that was Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-248618 Share on other sites More sharing options...
k2snowman69 Posted May 9, 2007 Author Share Posted May 9, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-248633 Share on other sites More sharing options...
john010117 Posted May 9, 2007 Share Posted May 9, 2007 Scroll down. It's on the left corner of the topic. Quote Link to comment https://forums.phpfreaks.com/topic/50028-solved-session-variable-help/#findComment-248639 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.