colbs Posted October 20, 2007 Share Posted October 20, 2007 hi! i'm in my second term learning PHP, and we are doing State Maintenance. here is the instructions to a lab I am working on, followed by the code I've written: Instructions: Create a function called login that takes all pieces of login data as parameters and returns a random integer that represents the evaluation id or false when the user enters something other than Students as the password. Maintain the evaluation id throughout the lifetime of the evaluation completion process. Code: function login($cN, $pW, $suF, $suL, $stF, $stL) { $success = true; $evalID = 1; if ($pW == "Students") { $success = true; return $evalID; } else return false; } I call this function on the front page using THIS code: if (count($_POST) > 0) { $success = login($cN, $pW, $suF, $suL, $stF, $stL); if ($success == false) echo "Invalid password"; else { $_SESSION['evalID'] = $evalID; header('location: q1.php'); } } i understand session_start() and the $_SESSION autoglobal, so I call them accordingly. My site just isn't maintaining state. For example, I can do this "$sessionID = session_id(); echo $sessionID;" and I will get the Id on the first page, but when I try and echo it on the next page, I get nothing. I've also set permissions on just about every darn folder I have connected to Inetpub and windows, and still nothing. can anyone help me? thanks c Quote Link to comment https://forums.phpfreaks.com/topic/74036-maintaining-state-not-working-need-help/ Share on other sites More sharing options...
redarrow Posted October 20, 2007 Share Posted October 20, 2007 place seesion_start on every page.... <?php session_start(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/74036-maintaining-state-not-working-need-help/#findComment-373794 Share on other sites More sharing options...
colbs Posted October 20, 2007 Author Share Posted October 20, 2007 true. i do that. and i also have an include_once('lab2functions.php'), which contains the login function. so something else is the cause. Quote Link to comment https://forums.phpfreaks.com/topic/74036-maintaining-state-not-working-need-help/#findComment-373796 Share on other sites More sharing options...
redarrow Posted October 20, 2007 Share Posted October 20, 2007 Post all your pages and code let's look and see ok.... Quote Link to comment https://forums.phpfreaks.com/topic/74036-maintaining-state-not-working-need-help/#findComment-373825 Share on other sites More sharing options...
colbs Posted October 20, 2007 Author Share Posted October 20, 2007 LOGIN.PHP <?php session_start(); include_once("lab2functions.php"); $cN = $_POST['coName']; $pW = $_POST['password']; $suF = $_POST['supFirstName']; $suL = $_POST['supLastName']; $stF = $_POST['studFirstName']; $stL = $_POST['studLastName']; if (count($_POST) > 0) { $success = login($cN, $pW, $suF, $suL, $stF, $stL); if ($success == false) echo "Invalid password"; else { $_SESSION['evalID'] = $evalID; header('location: q1.php'); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> Welcome, Log-In. </title> </head> <body bgcolor = "black", text="white"> <p> <h2> Welcome. Please Log In. </h2> </p> <p> <table> <form name="login" method="post" action="q1.php" onsubmit="return validateForm();"> <tr> <td>Company Name:</td> <td><input type="text" name="coName" id="coName"></td> </tr> <tr> <td>Password:</td> <td><input type="text" name="password" id="password"></td> </tr> <tr> <td>Supervisor First Name: </td> <td><input type="text" name="supFirstName" id = "supFirstName"></td> </tr> <tr> <td>Supervisor Last Name: </td> <td><input type="text" name="supLastName" id="supLastName"></td> </tr> <tr> <td>Student First Name: </td> <td><input type="text" name="studFirstName" id="studFirstName"></td> </tr> <tr> <td>Student Last Name: </td> <td><input type="text" name="studLastName" id="studLastName"></td> </tr> <tr> <td><input type="submit" name="submit" id="submit" value="Log In"> <input type="submit" name="clear" id="clear" value="Clear"></td> </tr> </form> </table> </p> </body> </html> LAB2FUNCTIONS.php function login($cN, $pW, $suF, $suL, $stF, $stL) { $success = true; $evalID = 1; if ($pW == "Student") { $success = true; return $evalID; } else $success = false; return $success; } ?> END thanks colbs Quote Link to comment https://forums.phpfreaks.com/topic/74036-maintaining-state-not-working-need-help/#findComment-373894 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.