User Logout Message

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
kkohlmorgen
Forum Newbie
Posts: 1
Joined: Fri Jun 24, 2011 1:05 pm

User Logout Message

Post by kkohlmorgen »

Hi there, I'm new to php development, and I need some assistance. I've created a login that uses the SESSION superglobal to authenticate the user. When the user logs in they are greeted by a message that includes their username. I do this through a function I created:

Code: Select all

function session_text($session_text_input) {
	$sql = "SELECT * FROM users WHERE uid = " . $_SESSION["uid"];
	$result = mysql_query($sql);
	$array = mysql_fetch_array($result);
	print_r ($array["$session_text_input"]);
}
The function works perfectly when the user logs in. However this is not the case when the user logs out. I would like to be able to have another message telling the user that they have logged out successfully with their username included in the message. This is difficult because I have already destroyed the session, therefor my function that calls the session in question no longer exists.

If anyone has any ideas or a work around, I would be very grateful. Thank you.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: User Logout Message

Post by pickle »

3 options, in order of best -> worst

1) Don't output the username. Once the user has logged out, there should be no indication they were ever there.
2) Write a new function to pull the info out of $_SESSION before it is destroyed, but return the string to output rather than echo-ing it.
1) Modify your function to accept another parameter - the username
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply