Jump to content

Maintaining State - Not Working - Need Help


Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/74036-maintaining-state-not-working-need-help/
Share on other sites

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

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.