Page 3 of 3
Re: need help on user login
Posted: Fri Aug 08, 2008 8:44 pm
by Stryks
Well ... we stored information into $_SESSION['user'] as an array so that we could keep track of it. Problem is, if you try to echo an array, it just says 'array'.
We used ...
Code: Select all
$_SESSION['user'] = array('id' => $data['id'], 'firstName'=>$data['firstName']);
... to store the data into the session ... so we should be able to specify what part of the array we want to echo with something like ...
Code: Select all
echo $_SESSION['user']['firstName'];
You might want to have a read of
THIS MANUAL PAGE to get up to speed on how arrays work.

Re: need help on user login
Posted: Fri Aug 08, 2008 10:11 pm
by zplits
thanks for the info sir. Still no luck, no name displayed, went back to display just the logout button
Re: need help on user login
Posted: Fri Aug 08, 2008 10:46 pm
by Stryks
Oh ... hang on ... we've taken a few steps backwards here.
The last time you posted checklogin.php ... you had this ...
Code: Select all
$_SESSION['user'] = array('id' => $data['id'], 'firstName'=>$data['firstName']);
But as you have not pulled that data from the database ....
Code: Select all
$sql="SELECT id FROM $tbl_name WHERE loginName='$myusername' and passWord='$mypassword'";
... $data['firstName'] is not available to set into the $_SESSION array. Remember, we can only use information from the database that we actually pull. You will know if you have pulled it because it will be named between the SELECT and FROM sections of your SQL query.
Given your DB schema, this ...
Code: Select all
$sql="SELECT id, firstName, lastName FROM $tbl_name WHERE loginName='$myusername' and passWord='$mypassword'";
... would be more appropriate.
So now you will have access to id, firstName and lastName. So seeing as we now have both of the users real names ... we might as well use them both.
Code: Select all
$_SESSION['user'] = array('id' => $data['id'], 'realName'=>$data['firstName'] . ' ' . $data['lastName']);
Now the $_SESSION array key is 'realname', not 'firstName', so we display it with ...
Code: Select all
echo $_SESSION['user']['realname'];
And all things being equal .. that should be all happy.

Re: need help on user login
Posted: Fri Aug 08, 2008 11:21 pm
by zplits
hey sir. That's it. I'm so happy we got it at last. Thank you very much for your help. Very much appreciated. How i wish i'm as good as you. I also want to help other people. I'm new in php but I'm kinda good in flash.

Wanna see some of my works?
Sir, can i ask you something about sessions?
Re: need help on user login
Posted: Sat Aug 09, 2008 2:41 am
by Stryks
We're rolling on sessions so why not. What you need to know?
If you want to get better and help people out, just keep working on your project and swing past here every so often. You can learn a whole lot by reading other peoples posts, and every so often, you might have something valuable to add.
Always happy to look .... drop a link if you have them online someplace.
Cheers
Re: need help on user login
Posted: Sat Aug 09, 2008 3:09 am
by zplits

yes sir. You're right. Sad to say I'm kinda busy right now. Because I'm a information technology graduating student, and I'm having my thesis. But I also spend time helping my classmates or schoolmates in their problems. Anyway i can help. I'll be glad to help.
Here is some of my flash works:
http://www.whatsthelatest.net/lfisher
http://www.whatsthelatest.net/kaisei
http://www.whatsthelatest.net/chickendeli
Here is my blog:
http://www.whatsthelatest.net
The site i have created for my church:
http://www.ioacjci.org
Hope you like it....
My question in session is, where should i put it? i mean should i put it in every page?
Re: need help on user login
Posted: Sat Aug 09, 2008 5:46 am
by Stryks
Nice work. I've never worked with flash .... have always been more content driven. But if I ever give it a go I might hit you up for some answers.
As for the sessions, basically, you need to include $session_start() on every page which will access $_SESSIONS in any way. So you'll need to have it on every page that is restricted to logged in users for example, so that you'll have the 'users' data to verify they are logged in. i.e. if it exists then they have logged in.
For the most part, it doesn't hurt to start them on every page anyhow.
Good luck
Re: need help on user login
Posted: Sat Aug 09, 2008 7:54 am
by zplits
Sure sir, I'll be glad to help in exchange.
Ahm. Should i insert:
Code: Select all
session_start();
if(!isset($_SESSION['user'])){
header("location:login.php");
}
in every page? or i'll just insert session_start();?
Re: need help on user login
Posted: Sat Aug 09, 2008 7:42 pm
by Stryks
The whole block will probably be best ...
This will mean that people who are not logged in will be sent back to the index page.
Re: need help on user login
Posted: Sun Aug 10, 2008 3:14 am
by zplits
Okay sir. Thank you very much all of your help and support. I really appreciate it. This login system won't be possible without your great and quick responses.
I am now planning to add a Lost your password? in the login system.
I hope you'll still help me. cheers. Your the man sir. Thanks for everything.