Page 1 of 1

global session variables

Posted: Thu May 08, 2003 4:20 am
by irealms
i want to make password a session variable to be used later for checking

can you tell me if this is right?

session_register("password"); //defines the variable as a session variable

session_is_registered("password") // to call it later when needed?

i want to use it in my change password form and was wondering if this is right

if (session_is_registered("password")!=$old_passwd)
echo "Your old password is incorrect<br />please try again.";

Posted: Thu May 08, 2003 4:30 am
by twigletmac
What version of PHP are you using? If it's 4.1 or greater then to set a session variable you would do:

Code: Select all

$_SESSION['foo'] = 'bar';
and to check that it's set and to display it:

Code: Select all

if (!empty($_SESSION['foo'])) {
    echo $_SESSION['foo'];
}
Have a read of:
viewtopic.php?t=6521

Mac

thanks

Posted: Thu May 08, 2003 7:08 am
by irealms
ok i'll give that a go, in the post you mentioned it defines the user , the variable i want to use is a users password from the database how would i point it to that?

tried this

Posted: Thu May 08, 2003 7:29 am
by irealms
in the login script where the password is entered i used

$_session['pass'] == $password;


then in the change password file i have

($_session['pass'] != $old_passwd)

it is saying the password is wrong even though it isnt atm :cry:

Posted: Thu May 08, 2003 7:32 am
by twigletmac
You need to use $_SESSION (all caps) not $_session. I also forgot to mention before that session_start() needs to be at the top of all scripts in which you set or access session variables.

Mac

yup

Posted: Thu May 08, 2003 7:38 am
by irealms
i will change that now, i've got the session_start() in a config file called into the pages, well the index page as all other files are called into that page.

http://www.irealms.co.uk/crimson

(

Posted: Thu May 08, 2003 7:45 am
by irealms
still no luck, it still says the password isn't right when it is :cry:

hehe

Posted: Thu May 08, 2003 7:55 am
by irealms
woot works now, i think :lol:

thanks for the help, just got to figure out how to make it change password in database now when succesful