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 Quote Link to comment Share on other sites More sharing options...
bwochinski Posted March 2, 2007 Share Posted March 2, 2007 <?php echo "Hello, $username"; ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 2, 2007 Share Posted March 2, 2007 is $username set as a session? Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
tkolbeck Posted March 2, 2007 Author Share Posted March 2, 2007 yes I have started a session Quote Link to comment 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" Quote Link to comment 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']." "; ?> Quote Link to comment Share on other sites More sharing options...
tkolbeck Posted March 2, 2007 Author Share Posted March 2, 2007 I still get "Hello, Login Successful" Quote Link to comment 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 Quote Link to comment 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"; } ?> Quote Link to comment 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> Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.