How to create socket connection with php?

Echo Username From SESSION PHP?

  • Hello, I am trying to create a members page for my website and I want it to display a welcome message for when the person views it, something like: "Welcome <USERNAME>" I am new to PHP so I am not sure if there is something I am doing wrong, here is what I have so far: For the Login Page <?php session_start(); $Connection = mysql_connect("localhost","root","passwo… or die ("Login Fail"); mysql_select_db("database") or die ("Cannot Find DB"); if(isset($_SESSION['Logged'])) { die(header ('Location: ../Pages/Members.php')); } $Username = strip_tags(strtolower($_POST['Username']… $Password = strip_tags(md5($_POST['Password'])); $mysql = mysql_query("SELECT * FROM Member_Data WHERE Username = '$Username' AND Password = '$Password'"); if(mysql_num_rows($mysql) < 1) { die(header('Location: Errors/Password.php')); } $_SESSION['Logged'] = "YES"; $_SESSION['Username'] = $Username; die(header('Location: ../Pages/Members.php')); ?> (I have removed my password and DB name from the code for safety reasons, but I know for a fact these are correct). And this is the part for displaying the message: <?php session_start(); { echo $_SESSION['Username'] or die (mysql_error()); } ?> When I try and echo it out, all I get is 'Welcome 1'. Originally I thought this was the ID in the database, because I was the first account I had that ID but when creating another account I still get the same message. Please could someone tell me what I am doing wrong and how to fix it, thanks!

  • Answer:

    I don't see any wrong with your code! I think you should replace 'Username' (string index) in both php files with another one for example 'User' I'm not sure but 'Username' may be already reserved by the PHP engine. Please try and let me know if it works! I'm sorry I want to confirm that the 'Username' I mentioned above is a string index not the variable $Username, that means the $_SESSION['Username'] in both php files should be rewritten as $_SESSION['User'] If it was exactly what you did but it still doesn't work, I'm sorry to say that I have no more clues on this. You can try checking the value of $Username before assigning it to the SESSION variable in the login php file, its value should be 1, otherwise I can't understand why the SESSION doesn't work! Hope another one can help you, if you fix the problem yourself, please post the solution to help me know what the puzzle is, thank you!

Octet at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.