How can I change or add things to my website when someone logs into it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I change or add things to my website when someone logs into it?

I'm making a huge project for school, and I already did the submit and login forms and they are working. I'm using php session, but I don't understand much about that language. I want to add a button of logout on my existing web, but only after the user login into my site. https://code.sololearn.com/WSclLB8xtwO4/?ref=app

13th Mar 2020, 10:10 AM
Fábio Gonçalves
Fábio Gonçalves - avatar
9 Answers
+ 2
Fábio Gonçalves I can't fill up on missing parts in your code. ATM I don't have access to a computer to test (I'm on mobile). I wrote that little example as an ilustration, an intro on how session can be used for such use cases. You can try find some complete examples on the net, there are plenty I believe. Search for examples that also includes examples about database usage, it will help in longer run 👍
15th Mar 2020, 3:08 PM
Ipang
+ 1
Thank you for giving this question attention. Well, I already started the session and all, but I don't know how it works. For example. I have a very good design. How can I make the session start and make the username pop up with a dropdown link in the navbar? I want to put that in my code. But only after it starts. Are you understading? I can explain you better in private. I think it's very easy to do, but I am very new at PHP.
13th Mar 2020, 8:28 PM
Fábio Gonçalves
Fábio Gonçalves - avatar
+ 1
Fábio Gonçalves In simple terms, as per my understanding, session is a file based storage. It works like cookies, but the difference is, the file is created on server side, not on client side (as per the tutorial). All session variable and their value are stored in a unique file in server. Your session storage file is not mixed with that created by another connection. This file might be deleted when client ends the session by closing browser, or when `session_destroy` is invoked. Is it possible that you can save a copy of the code in SoloLearn and share the link? I just think that maybe more people can contribute in this discussion, and possibly help if they can see your code. Follow the guide below in case you didn't know how to share links 👇 https://www.sololearn.com/post/74857/?ref=app
14th Mar 2020, 5:20 AM
Ipang
+ 1
I already added my code. The thing I wanna do is simple. Just adding a button to logout of the session in my website after a user login.
14th Mar 2020, 5:43 PM
Fábio Gonçalves
Fábio Gonçalves - avatar
+ 1
Fábio Gonçalves I made this sample, it's very very basic, but I hope it gives you an idea on how login-logout works in simple way. https://code.sololearn.com/witLvrO0HpBb/?ref=app
15th Mar 2020, 6:47 AM
Ipang
+ 1
Thank you a lot for you attention, but can you make a code from what's missing in mine? Like, I just want to make a logout button after he logs in while using my HTML page. That would help me a lot more since I don't understand much about PHP. You are awesome.
15th Mar 2020, 1:59 PM
Fábio Gonçalves
Fábio Gonçalves - avatar
+ 1
Thank you.
16th Mar 2020, 11:37 AM
Fábio Gonçalves
Fábio Gonçalves - avatar
+ 1
No problem 👌
16th Mar 2020, 11:39 AM
Ipang
0
"How can I change or add things to my website when someone logs into it?" More information needed, what to add or change? If you already have a working register / login mechanism, then it shouldn't be that hard to implement a logoff feature. Can you clearly describe where you got stuck on this plan? Session in PHP Tutorial, in case you forgot: https://www.sololearn.com/learn/PHP/1842/
13th Mar 2020, 10:52 AM
Ipang