php login logout form display data from database -



php login logout form display data from database -

i have 3 questions code.

how can display user's name logged profile.php file? because current code display's every username no matter logs in.

how can restrict profile.php page can seen if user logged in?

how can create logout page works?

below code in order each file config.php //connect info base, login.php, profile.php, , logout.php:

//------------------------config.php--------------- <?php mysql_connect("localhost","root",""); mysql_select_db("login2"); ?> //------------------------login.php--------------- <?php session_start(); require('config.php'); if(isset($_post['submit'])){ $uname = mysql_escape_string($_post['uname']); $pass = mysql_escape_string($_post['pass']); $salt = ''; $pass = md5 ($pass . $salt); $sql = mysql_query ("select * `users` `uname` = '$uname' , `pass`= '$pass' "); if(mysql_num_rows($sql) > 0){ header('location: profile.php'); exit(); }else{ echo "wrong password or username"; } }else{ $form = <<<eot <form action="login.php" method="post"> username : <br /> <input type="text" name="uname" /> <br /> <br /> password : <br /> <input type="password" name="pass" /> <br /> <br /> <input type="submit" name="submit" value="log in" /> </form> eot; echo $form; } ?> //------------------------profile.php--------------- <?php require('config.php'); ?> <html> <head> </head> <body> <?php $sql = mysql_query("select * users "); while($row = mysql_fetch_array($sql)){ $name = $row['name']; $lname = $row['lname']; $uname = $row['uname']; } ?> <p>welcome <b><?php echo $name; ?></b></p> <a href="logout.php">logout</a> </body> </html> //------------------------logout.php--------------- <?php require('config.php'); session_destroy(); header('location: login.php'); exit(); ?>

the reply questions: utilize $_sessions in php. forgot mention, need have session_start() @ top of every page on plan on using $_session.

// user login if(mysql_num_rows($sql) > 0){ $_session['user_name'] = $_post['uname']; header('location: profile.php'); exit(); }else{ echo "wrong password or username"; } // profile (check if user logged in) if(isset($_session['user_name']) && !empty($_session['user_name'])){ // show page }

how can create logout page works?

you're going need start reading, recommend great new book called google.

php login logout

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -