Page 1 of 1

Define session variable

Posted: Wed Jun 15, 2005 9:36 am
by ljCharlie
I kept getting the following error:
Notice: Undefined variable: _SESSION in F:\wwwroot\home\mywebsite\emlSearch.php on line 33
Below is how I define my session variables:

Code: Select all

session_start();

	//declare three session variables and assign them
    $GLOBALS['MM_Username'] = $loginUsername;
	$GLOBALS['MM_Password'] = $password;
    $GLOBALS['MM_UserGroup'] = $loginStrGroup;	 
    
	//register the session variables
	$_SESSION['MM_Username'] = $loginUsername;
	$_SESSION['MM_Password'] = $password;
	$_SESSION['MM_UserGroup'] = $loginStrGroup;

    session_register("MM_Username");
    session_register("MM_UserGroup");
	session_register("MM_Password");
Any help is much appreciated.

ljCharlie

Posted: Wed Jun 15, 2005 9:59 am
by hawleyjr
$_SESSION entries are automatically registered. You don't need to use session_register()

http://us4.php.net/manual/en/function.s ... gister.php

Posted: Wed Jun 15, 2005 10:20 am
by ljCharlie
Thank you for the response. I took the register code off and still not working. It kept saying undefine variable _Session when I did this:

Code: Select all

echo "User Name: ".$_SESSION['MM_Username']." Password: ".$_SESSION['MM_Password']."<br>";

ljCharlie

Posted: Wed Jun 15, 2005 10:43 am
by shiznatix
you gotta assign the session variables first

Code: Select all

session_start();//dont forget that part

$_SESSION['thingy'] = 'not my thingy!';

echo $_SESSION['thingy'];

Posted: Wed Jun 15, 2005 10:47 am
by ljCharlie
I already assigned it right here:

Code: Select all

//register the session variables
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_Password'] = $password;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;
I assigned the variable in my login page. I want to retrieve the information back once the user logged in.

ljCharlie

Posted: Wed Jun 15, 2005 10:52 am
by ol4pr0
hawleyjr wrote:$_SESSION entries are automatically registered. You don't need to use session_register()
Well he does need to use session_register(); unless php.ini says differant.

--
and when calling a $_SESSION['whateverVar'] you need to use it again session_register(); and then call the $_SESSION variable.

ps:

Notice: Undefined variable: _SESSION in F:\wwwroot\home\mywebsite\emlSearch.php on line 33 <--

I only count 15 lines in ure posted code.

EDIT::
Sorry he doesnt need to use session_register!
Meant: session_start(); :)[/b]

Posted: Wed Jun 15, 2005 10:55 am
by ljCharlie
Line 33 refers to this line:

Code: Select all

echo "User Name: ".$_SESSION['MM_Username']." Password: ".$_SESSION['MM_Password']."<br>";

Posted: Wed Jun 15, 2005 10:59 am
by shiznatix
did you put session_start(); at the top of the page? cause its saying that these variables are not assigned. you have to have session_start(); at the top of every page that is going to use the sessions

Posted: Wed Jun 15, 2005 11:05 am
by ol4pr0
And that's on the same page ?
if so you need to refresh the page before echoing the $_SESSION, or just another page.

try this.

Code: Select all

session_start();
$_SESSION&#1111;'trying'] ='Hello there';
echo &quote;&lt;a href='/show.php'&gt;Continue&lt;/a&gt;&quote;;
?&gt;

Code: Select all

session_start();
$s_set = $_SESSION&#1111;'trying'];
if ($s_set) {
echo $s_set;
}else{
echo &quote;You have a problem&quote;;
}

Posted: Wed Jun 15, 2005 11:07 am
by ljCharlie
Problem solved! shiznatix was right. I totally forgot about having the session_start(); at the beginning. I thought I only need it when declaring and assigning...not when retreiving..well, it works now.

Thank you very much for the help.

ljCharlie

Posted: Wed Jun 15, 2005 11:51 am
by shiznatix
glad to be of service