php - Login functionality in HTML page -
php - Login functionality in HTML page -
i have created html page takes user-id , password user , check there validity through database. till directing them page after successful login. want update same page after login. www.facebook.com ; when not logged in asks user-id , password, if login our profile contents displayed on same page i.e. facebook.com. doing; directing page "login.php" of course of study can access without login.
for illustration there page "movies.com" allows user watch movies after login; before directing them page "successful_login.com" after login. funny approach, working college assignments.
ps. noob, sorry if asked funny.
<?php if(mysql_connect("localhost","root","")==false) { die ("connection failed"); } mysql_select_db("data"); if($_post) { $id=$_post["email"]; $pwd=$_post["password"]; $pwd=hash( 'sha256', $pwd); $sql=mysql_query("select* admin_data id='$id' , pass='$pwd'"); if($sql) { header("location: login.php"); } } ?> <!doctype html> <html lang='en'> <head> <meta charset="utf-8" /> <title> html document construction </title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <form method="post"> <h1>welcome</h1> <div class="inset"> <p> <label for="email">login</label> <input type="text" name="email" id="email"> </p> <p> <label for="password">password</label> <input type="password" name="password" id="password"> </p> </div> <p class="p-container"> <span>forgot password ?</span> <input type="submit" name="login" id="login" value="log in"> </p> </form> </body> </html>
to utilize session
variable need start session
@ top.
session_start();
now store email
value in session in here.
if(mysql_num_rows()>0)//it if($sql)but using mysql_num_rows //the reason saving value in session here this. first want create sure user have valid credential log in. { $_session['email']=$id header("location: login.php"); }
in form can
session_start();
//start session @ top can utilize session variable.
then utilize if
else
statement.
if($_session['email']==true) { $email=$_session['email']; //now can run query using $email fetch record of user. } else { //show them form or redirect them page. }
note:mysql
deprecated , going dropped soon. utilize mysqli
or p.d.o
php html
Comments
Post a Comment