php - How to register a session for variable and how to use that in another pages for maintain a user with username or password -
i want know how register session variable , how use in pages maintaining user username or password .
my code follows:
login.php
<?php session_start(); include('connect.php'); $name = $_post['name']; $password = $_post['password']; $role = $_post['member']; $sql = "select * login_register name = '$name' , password = '$password' , role = '$role'"; $retain = mysql_query($sql, $con); // mysql_num_row counting table row $count=mysql_num_rows($retain); // if result matched $myusername , $mypassword, table row must 1 row if($count == 1){ // register $myusername, $mypassword , redirect file "login_success.php" $_session['name']=$name; //header("location:admin_home.php"); if ( $role == "admin") { header("location:admin_home.php"); } else if ( $role == "member") { header("location:member_home.php"); } } else { echo "wrong username , password <a href='index.php'>click here login </a>"; } ?>
admin_page.php
<?php // starts session session_start(); // sets variables in session $_session['name']="name"; print "done"; ?> <html> welcome admin <a href="admin_logout.php"> logout </a> </html>
i dont want see user page without going via login credinals..
store session like: $_session['username'] = "your username";
and on next page check if session set with: if(isset($_session['username'])){ echo $_session['username'];}
Comments
Post a Comment