supermerc Posted March 6, 2007 Share Posted March 6, 2007 Hi I'm trying to welcome my members so when they come in to my page it will say welcome, Your Name, You are logged in as Username. <? session_start(); require("config.php"); require("functions.php"); echo '<p>Welcome, '.$_SESSION['s_name'].',</p>'; echo '<p>You are logged in as '.$_SESSION['s_username'].'.</p>'; ?> But It doesnt show the username, for some reason it shows the database username... Here is my login script, incase you need it to help: <?php session_start(); require("config.php"); require("functions.php"); //echo some styles to spice it up... echo " <style> body { background: #ffffff; font-family: Verdana, Arial; font-weight: bold; font-size: 9px; color: #000000; } .register_box { border: 1px solid #323232; background: #202020; font-family: Verdana, Arial; font-weight: bold; font-size: 9px; color: #FFFFFF; } </style> "; if(!isset($_SESSION['logged_in'])) { if(!isset($_POST['check_login'])) { echo " <form action='login.php' method='post'> Username: <input type='text' name='username' /> <br /> Password: <input type='password' name='password' /> <br /> <input type='submit' name='check_login' value='Login' /> </form> "; } elseif(isset($_POST['check_login'])) { $username = mysql_real_escape_string($_POST['username']); $password = md5($_POST['password']); if(empty($_POST['password']) || empty($username)) { echo "You left a field blank!"; } else { $check_login = mysql_query("SELECT username, password, id FROM user_system WHERE username = '$username' AND password = '$password' LIMIT 1"); if(mysql_num_rows($check_login) > 0) { $_SESSION['logged_in'] = 1; $_SESSION['username'] = $username; echo "You have been successfully logged in!"; } else { echo "Sorry. Wrong password, or user does not exist."; } } } } else { echo "You are already logged in."; } ?> Thank you. Link to comment https://forums.phpfreaks.com/topic/41529-sessions/ Share on other sites More sharing options...
bwochinski Posted March 6, 2007 Share Posted March 6, 2007 $_SESSION['username'] = $username; You call it 'username' in your login script, not 's_username'. And for that matter I can't see where the 's_name' is coming from. Link to comment https://forums.phpfreaks.com/topic/41529-sessions/#findComment-201194 Share on other sites More sharing options...
trq Posted March 6, 2007 Share Posted March 6, 2007 You never set any values in $_SESSION['s_name'] or $_SESSION['s_username'] in your login script. Try $_SESSION['username'] as is set in your login script. Link to comment https://forums.phpfreaks.com/topic/41529-sessions/#findComment-201197 Share on other sites More sharing options...
willpower Posted March 6, 2007 Share Posted March 6, 2007 yes thats right you have echo $_SESSION['s_username'] ...change that Link to comment https://forums.phpfreaks.com/topic/41529-sessions/#findComment-201198 Share on other sites More sharing options...
supermerc Posted March 6, 2007 Author Share Posted March 6, 2007 Ya, its when i have $_SESSION['username'] That it gives my my database name/username instead of the username. the s was from my old script, and name if for something im going to do later on. But ya, $_SESSION['username'] doesnt work. Link to comment https://forums.phpfreaks.com/topic/41529-sessions/#findComment-201209 Share on other sites More sharing options...
supermerc Posted March 6, 2007 Author Share Posted March 6, 2007 If you want to go see, http://random.awardspace.biz/ is site, you can use test//ilmilm or supermerc/ilmilm to login, you will see it gives supermerc_random for both, which is database name/username. Link to comment https://forums.phpfreaks.com/topic/41529-sessions/#findComment-201210 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.