authentication - Login System using PHP -
authentication - Login System using PHP -
i'm new in php. newbie, started first project. made login scheme webapp. there's problem. when seek access index or main page, asks login, when i'm seek access other page, doesn't inquire me login.
how can manage same restriction pages? login code here.
<? $connection=mysql_connect("localhost","admin",""); if(!$connection) { die("database connection failed: " . mysql_error()); } //select database utilize $db=mysql_select_db('vss',$connection); if(!$db) { die("database selection failed: " . mysql_error()); } $username=$_post['username']; $password=$_post['password']; // $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); // $query="select *from user username='$username'and password='$password'"; $result=mysql_query($query); $count=mysql_num_rows($result); // if result matched $username , $password,table row must 1 row if($count==1){ // register $username, $password , redirect file "example.php" session_register("username"); session_register("password"); header("location:http://localhost/vss/main.php"); } else { echo "wrong username or password"; } ?> i added:$userok=$count;after line $count==1 added added:$userok=$count;after line $count==1 added call.php-><?php if($userok!=1); { header("location:localhost/vss/logindo.php";); } ?> added include(call.php) in top of restricted pages.but,when click button every time inquire login.how can create logged user until press "logout". added include(call.php) in top of restricted pages.but,when click button every time inquire login.how can create logged user until press "logout".
i won't discuss security of since learning. following: 1) below line if($count==1) add together $userok=1; , on else part add together $userok=0; 2) rename above .php init.php, 3) on top of other pages "
include ('init.php'); if (!($userok==1)) { echo "please not phone call directly, login first"; exit; } you replace echo "please login" header("location: http://...") redirecting login page.
php authentication
Comments
Post a Comment