Skip to content
Advertisement

Why is the php session password being shown in a var_dump instead of the username?

I’m using the demo from this page: https://www.w3schools.in/php-script/php-login-without-using-database/ and if I add this to the index page:

<?php
var_dump($_SESSION);
?>

It’s returning the password not the username and I can’t figure out how to correct this. Can anyone help please? I’d like to be able to display the name of the user who logged in.

Advertisement

Answer

This is what you are storing:

$_SESSION['UserData']['Username']=$logins[$Username]

And that value you have already checked it:

logins[$Username] == $Password

So it is showing the password because you are storing the password.

If you want to store the username, then store $Username.


This is one more example of W3Schools being dreadful. I strongly suggest avoiding it.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement