How to register a session for variable and how to use that in another pages for maintain a user with username or password <p>I want to know how to register a session for variable and how to use that in another pages for maintaining a user with username or password .</p> <p>My code is as follows: </p> <p>Login.php</p> <pre><code>&lt;?php session_start(); include('connect.php'); $name = $_POST['name']; $password = $_POST['password']; $role = $_POST['member']; $sql = "select * from login_register where name = '$name' and password = '$password' and role = '$role'"; $retain = mysql_query($sql, $con); // Mysql_num_row is counting table row $count=mysql_num_rows($retain); // If result matched $myusername and $mypassword, table row must be 1 row if($count == 1){ // Register $myusername, $mypassword and redirect to 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 and password &lt;a href='index.php'&gt;click here to login &lt;/a&gt;"; } ?&gt; </code></pre> <p>admin_page.php</p> <pre><code>&lt;?php // this starts the session session_start(); // this sets variables in the session $_SESSION['name']="name"; print "Done"; ?&gt; &lt;html&gt; Welcome admin &lt;a href="admin_logout.php"&gt; logout &lt;/a&gt; &lt;/html&gt; </code></pre> <p>I dont want to see the user this page without going via login credinals.. </p>