Page 1 of 1

session problem

Posted: Fri Oct 22, 2004 1:19 pm
by Kingo
Hello,
I'm getting the following error when I changed all the code from one server to other.

Undefined index: TEACHER_ID in general.php on line 95

Code: Select all

function authenticate_user($p_LDAP_ID, $p_PASSWORD = '')
	{
		global $connection;

		$query = "SELECT * FROM TEACHERS T, SCHOOLS S WHERE T.SCHOOL = S.SCHOOL(+) AND LDAP_ID = '$p_LDAP_ID'";

		$oci = new oci_query($query, $connection);

		if ($oci->num_rows() == 0)
			return false;
		else
		{
			return $oci->fetch_array();
		}
	}

	function print_header()
	{
		global $connection;
		global $page_start_time;

		$page_start_time = utime();

		// verify session
		if (!isset($_SESSION['TEACHER_ID']))
		{
			$auth_data = authenticate_user($_SERVER['REMOTE_USER']);

			if ($auth_data)
			{
				$_SESSION['TEACHER_ID'] = $auth_data['TEACHER_ID'];
				$_SESSION['LAST_NAME'] = $auth_data['LAST_NAME'];
				$_SESSION['FIRST_NAME'] = $auth_data['FIRST_NAME'];
				$_SESSION['HOMEROOM'] = (isset($auth_data['HOMEROOM']) ? $auth_data['HOMEROOM'] : '');
				$_SESSION['LDAP_ID'] = $auth_data['LDAP_ID'];
				$_SESSION['ACCESS_PRIV'] = $auth_data['ACCESS_PRIV'];

				if ($_SESSION['ACCESS_PRIV'] != 'D')
				{
					$_SESSION['SCHOOL'] = $auth_data['SCHOOL'];
					$_SESSION['SCHOOL_NAME'] = $auth_data['NAME'];
				}
				else
					$_SESSION['SCHOOL_NAME'] = 'Norfolk Public Schools';

				if ($_SESSION['ACCESS_PRIV'] == 'T')
				{
					// grab a list of grades they teach (only if it's a teacher)
					$query = "	select distinct GRADE
								  from STU_ENR
								 where HOMEROOM = '{$_SESSION['HOMEROOM']}'
								   and SCHOOL = '{$_SESSION['SCHOOL']}'";

					$result = new oci_query($query, $connection);

					while ($row = $result->fetch_array())
					{
						$_SESSION['GRADES'][] = $row['GRADE'];
					}
				}
				else
					$_SESSION['GRADES'] = array('KG', '01', '02');

				setcookie('LDAP_ID', $_SESSION['LDAP_ID'], strtotime('next year'));

				//redirect('index.php?welcome', true);
			}
			else
			{
				print '<span style="color: red;">Your account is not in the system.</span>';

				oci_disconnect();

				exit;
			}
		}
?>

Line 95 is

Code: Select all

$_SESSION['TEACHER_ID'] = $auth_data['TEACHER_ID'];


Any help is really really appreciated

Posted: Fri Oct 22, 2004 1:23 pm
by rehfeld

Code: Select all

<?php
$auth_data['TEACHER_ID'];
?>
does not exists yet is why(you have not set it, or you set it to a null value)

oh and its not session related

Posted: Fri Oct 22, 2004 1:30 pm
by Kingo
where and how do i set it to null value?

Posted: Fri Oct 22, 2004 4:07 pm
by timvw
where are you calling [php_man]session_start[/php_man] ?

Posted: Fri Oct 22, 2004 5:15 pm
by rehfeld
i am saying you have NOT set it yet.

so to solve your problem, you need to set it

Code: Select all

<?php
$auth_data['TEACHER_ID'] = 'value';
?>
undefined index means it doesnt exist.

$auth_data exists, it if didnt, the warning would be "undefined variable"

but there is no 'TEACHER_ID' in the $auth_data array


oh and doing this:

Code: Select all

<?php

$var = null;

?>
effectively does absolutely nothing
it is the same as saying the variable named $var, does not exist.
its like doing unset($var);


so if your database is returning the value of null for the TEACHER_ID variable, thats prob why your getting the undefined index error. either that, or your db query just doesnt even return TEACHER_ID at all.

remember,

$var = null;

is totally different than
$var = '';

the $var = ''; means $var exists, but has no value.
the $var = null; means $var does NOT exist.



Code: Select all

<?php

$auth_data = array();

$auth_data['TEACHER_ID'] = 'something';

echo $auth_data['TEACHER_ID']; // outputs: something

$auth_data['TEACHER_ID'] = '';

echo $auth_data['TEACHER_ID']; // outputs nothing, because theres no value

$auth_data['TEACHER_ID'] = null;

echo $auth_data['TEACHER_ID']; // error, this variable no longer exists


?>
make sense?