tkolbeck Posted March 2, 2007 Share Posted March 2, 2007 I need a code that prints "Hello, $username" code can anybody help me by wrighting this out for me? I have the variable $username for the username. Thanks, Tylor Link to comment https://forums.phpfreaks.com/topic/40885-show-logged-in-user/ Share on other sites More sharing options...
bwochinski Posted March 2, 2007 Share Posted March 2, 2007 <?php echo "Hello, $username"; ?> Link to comment https://forums.phpfreaks.com/topic/40885-show-logged-in-user/#findComment-197991 Share on other sites More sharing options...
redarrow Posted March 2, 2007 Share Posted March 2, 2007 is $username set as a session? Link to comment https://forums.phpfreaks.com/topic/40885-show-logged-in-user/#findComment-197998 Share on other sites More sharing options...
tkolbeck Posted March 2, 2007 Author Share Posted March 2, 2007 i am sorry but you are going to have to bare with me because I am a beginner and learning. How do I know if $username is set i nteh session or what should it look like? Link to comment https://forums.phpfreaks.com/topic/40885-show-logged-in-user/#findComment-198001 Share on other sites More sharing options...
redarrow Posted March 2, 2007 Share Posted March 2, 2007 when you login you set a session to the users name did you do that? Link to comment https://forums.phpfreaks.com/topic/40885-show-logged-in-user/#findComment-198002 Share on other sites More sharing options...
tkolbeck Posted March 2, 2007 Author Share Posted March 2, 2007 yes I have started a session Link to comment https://forums.phpfreaks.com/topic/40885-show-logged-in-user/#findComment-198005 Share on other sites More sharing options...
tkolbeck Posted March 2, 2007 Author Share Posted March 2, 2007 Here is the code that I am using: <? session_start(); if(!session_is_registered(myusername)){ header("location:index.php"); } echo "Hello, $username"; ?> <html> <body> Login Successful </body> </html> and it doesnt show that it outputs "Hello,Login Successfull" Link to comment https://forums.phpfreaks.com/topic/40885-show-logged-in-user/#findComment-198007 Share on other sites More sharing options...
redarrow Posted March 2, 2007 Share Posted March 2, 2007 try this then. <?php session_start(); echo "Hello, ".$_SESSION['username']." "; ?> Link to comment https://forums.phpfreaks.com/topic/40885-show-logged-in-user/#findComment-198008 Share on other sites More sharing options...
tkolbeck Posted March 2, 2007 Author Share Posted March 2, 2007 I still get "Hello, Login Successful" Link to comment https://forums.phpfreaks.com/topic/40885-show-logged-in-user/#findComment-198012 Share on other sites More sharing options...
tkolbeck Posted March 2, 2007 Author Share Posted March 2, 2007 I got it! thanks sorry again but could you tell me how to make it so it says hello, guest if there is no session? thanks Link to comment https://forums.phpfreaks.com/topic/40885-show-logged-in-user/#findComment-198013 Share on other sites More sharing options...
redarrow Posted March 2, 2007 Share Posted March 2, 2007 <?php session_start(); if($_SESSION['username']){ echo "Hello, ".$_SESSION['username']." "; }else{ echo "Hello Guest"; } ?> Link to comment https://forums.phpfreaks.com/topic/40885-show-logged-in-user/#findComment-198015 Share on other sites More sharing options...
tkolbeck Posted March 2, 2007 Author Share Posted March 2, 2007 Now I am getting this error: Parse error: parse error, unexpected $ in /home/www/bbbshops.com/login_success.php on line 28 when there is nothing on line 28 Here is my code <?php session_start(); if(!session_is_registered(myusername)){ header("location:index.php"); } if(session_is_registered(myusername)){ echo "Hello, ".$_SESSION['myusername']." "; } else { echo "Hello Guest" ?> <html> <body> Login Successful </body> </html> Link to comment https://forums.phpfreaks.com/topic/40885-show-logged-in-user/#findComment-198023 Share on other sites More sharing options...
Adika Posted March 2, 2007 Share Posted March 2, 2007 Hi! Here is the right code: <?php session_start(); if(!session_is_registered(myusername)){ header("location:index.php"); } if(session_is_registered(myusername)){ echo "Hello, ".$_SESSION['myusername']." "; } else { echo "Hello Guest" ?> <html> <body> Login Successful </body> </html> <?php } Do you see your mistake now? All the best, Adika Link to comment https://forums.phpfreaks.com/topic/40885-show-logged-in-user/#findComment-198109 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.