Imad Posted June 24, 2008 Share Posted June 24, 2008 Hi guys, I need some help with retrieving the user login. After the user logs in, a cookie is set. Is their anyway I can grab the username that he logged in with? I need this so I can echo who he's logged in as. Best Regards. Link to comment https://forums.phpfreaks.com/topic/111657-solved-how-to-retrieve-user-login/ Share on other sites More sharing options...
waynew Posted June 24, 2008 Share Posted June 24, 2008 $username = $_POST['username']; echo $username; Link to comment https://forums.phpfreaks.com/topic/111657-solved-how-to-retrieve-user-login/#findComment-573198 Share on other sites More sharing options...
waynew Posted June 24, 2008 Share Posted June 24, 2008 My bad, you said cookie. http://www.w3schools.com/PHP/php_cookies.asp Link to comment https://forums.phpfreaks.com/topic/111657-solved-how-to-retrieve-user-login/#findComment-573199 Share on other sites More sharing options...
revraz Posted June 24, 2008 Share Posted June 24, 2008 Cookies or no cookies, if he used a username to log in with, why not just store that in a session while they are on your site? Link to comment https://forums.phpfreaks.com/topic/111657-solved-how-to-retrieve-user-login/#findComment-573200 Share on other sites More sharing options...
waynew Posted June 24, 2008 Share Posted June 24, 2008 Exactly $_SESSION['username'] = $username; Link to comment https://forums.phpfreaks.com/topic/111657-solved-how-to-retrieve-user-login/#findComment-573246 Share on other sites More sharing options...
Imad Posted June 24, 2008 Author Share Posted June 24, 2008 Thanks for your replies guys. I tried doing something like this: if (isset($_SESSION['valid_user'])) { echo "$username"; } The session that is set with the cookie looks like this: $_SESSION['valid_user'] = $username; It didn't work, I just get a blank output. Any Ideas, Thanks. Link to comment https://forums.phpfreaks.com/topic/111657-solved-how-to-retrieve-user-login/#findComment-573683 Share on other sites More sharing options...
trq Posted June 24, 2008 Share Posted June 24, 2008 session_start(); if (isset($_SESSION['valid_user'])) { echo $_SESSION['valid_user']; } Link to comment https://forums.phpfreaks.com/topic/111657-solved-how-to-retrieve-user-login/#findComment-573687 Share on other sites More sharing options...
xtopolis Posted June 24, 2008 Share Posted June 24, 2008 <?php if (isset($_SESSION['valid_user'])) { $username = $_SESSION['valid_user']; } echo "You are logged in as $username"; ?> Set username = to the session var., or just echo $_SESSION['valid_user']; Link to comment https://forums.phpfreaks.com/topic/111657-solved-how-to-retrieve-user-login/#findComment-573688 Share on other sites More sharing options...
Imad Posted June 24, 2008 Author Share Posted June 24, 2008 Now it works. I already had the session_start() since I switch the signup button, login, etc to other links after login. I just couldn't get the username to work. Thanks a lot guys! Link to comment https://forums.phpfreaks.com/topic/111657-solved-how-to-retrieve-user-login/#findComment-573689 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.