Sessions help

Hi all, I am new to php but have experience with C++, Java, sql, etc.
Been digging into the php books and it looks pretty cool.

PHPStorm, mysql, and webplus all installed on Win 7/64 and working fine.

My question is about sessions. I am developing a website that will have multiple users logged in at the same time and need to use an instant messenger on the site.

So far I have not been able to determine from my reference books how I can differentiate users when they want to send an IM. I would like to know who is sending an IM so I can prefix their message with their login name. I know I can store the users logged in into the $_SESSION array but how to know who is sending the message?

Thanks for any help.

Let’s say in your login script you fetch details from the database and set up some sessions.
If, for example you have a variable like so -
Note: $username is set from information pulled from the database.
[php]$_SESSION[‘username’] = $row[‘username’];[/php]

Then if you and I login in on our respective machines this variable will hold my username within my browser and your username within yours so you can safely do something like this:
[php]INSERT INTO messages_table (name) VALUES ({$_SESSION[‘username’]})[/php]

Make sense?
Red :wink:

Thanks Redscouse. None of my php books seemed to make it clear that the $_SESSION values would be unique to each logged in user if I set them as part of the login process. This gives me a pretty good idea of how to proceed.

You’re welcome :slight_smile:
Have a read of this, it may help a little more. :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service