Skip to content
Advertisement

SQL database value to variable

So, I am kinda new to php and mysql, but I have found a login form and adapted it to my needs as I dont have the knowledge to make one my self yet. I added a firstname and surname column into the database and the register form adds the values into the database fine.

Now I want to be able to display the firstname and surname onto a restricted page, the reason why I need this is because I want it to say: Welcome Jo Blogs. Below is the register form.

And below here is the login form as im not really sure what you guys need to help me 🙂

Also while I am here, I am currently using javascript to redirect to the homepage once you log out as i couldn’t find any information on how to do it with php

Restricted.php:

Just let me know if you guys need any more information/code.

Thanks.

Advertisement

Answer

As Qirel suggested…

Restricted.php should resemble this:


Edit:

This statement borders on too serious but I would like to mention, especially to inexperienced php coders, that SESSION data can be hijacked (this is outlined in Pro PHP Security: From Application Security Principles to the Implementation of XSS Defense – Chapter 7: Preventing Session Hijacking) and so it can be suggested to never store any personal information in $_SESSION. This would most critically include credit card numbers, government issued ids, and passwords; but would also extend into less assuming data like usernames, emails, phone numbers, etc which would allow a hacker to impersonate/compromise a legitimate user.

The internet is still very much in its “Wild West” era, and nothing is 100% safe. …and Internet Security is a rabbit hole / money pit. Every coder should devote some time to understanding known threats and preventing them, but just how far to go with this will differ from person to person.

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