global session variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

global session variables

Post 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.";
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

thanks

Post 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?
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

tried this

Post 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:
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

yup

Post 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
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

(

Post by irealms »

still no luck, it still says the password isn't right when it is :cry:
User avatar
irealms
Forum Contributor
Posts: 215
Joined: Mon Apr 28, 2003 7:10 am
Location: Leeds

hehe

Post 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
Post Reply