php - How can I use Session Variables to output login username -
i'm building application , have added login page works well, communicating "username" , "password" field in database. after logging in, takes page users authorized see.
is there way can display "welcome, xxx" particular user logged in @ next page? , more importantly, output detailed information of logged in user on next page? thanks.
you can use session temporarily store data can seen across page.... after checking successful login credential, can stores user data in session
<?php session_start(); $_session['username'] = $user_name; ?>
after storing user data in session,you can access data across different pages until unset session data
<?php session_start(); if (!isset($_session['username'])) { echo 'welcome, '.$_session['username']; } else { echo 'sorry, not logged in.'; } ?>
when user logged out,unregister session variable. unregistering of session variable can done in following way:
<?php session_start(); unset($_session['username']); ?>