-1

I'm trying to use Session in this basic login page. Where and how do I use Session? Thanks. I saw many examples of use of session but please pinpoint where I can add it. I am new to PHP coding.

<!DOCTYPE html>
<html>
<head>

        <title>Login Page</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>

 <h1><b><center> Login Form</center></b></h1><br>

                <form method="post" action="loginn.php">

                <!--class in css can be defined and used here. need to check how?-->    
                <center><input type="tel" class="form-control" name="Mobile_No" placeholder="Please enter your Mobile No" required="true"  style='width:30em' pattern="[0-9]{10}">

                <br><br>
                <center> <input type="password" class="form-control" name="Password" placeholder="Please enter password here" required="true" style='width:30em' >
                <br><br>
                <center>  <input type="submit" class="btn btn-primary" value="Login">
                </form> 

            <br><br><br><br>


<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
</body>
</html>
  • 1
    few notes: 1) center has now been removed from the HTML markup - center stuff using CSS 2) don't use inline styles, it's hard-to-read and hard-to-maintain. 3) b is also not preferred, use `` instead – treyBake Apr 25 '19 at 09:55
  • what have you tried with `$_SESSION`? you only need to use it in the login validation -not the login form (well, I guess you could and should check if user is already logged in - but come to that later) – treyBake Apr 25 '19 at 09:55
  • `$_SESSION` has to set in the page where you handle login validation(In your case - loginn.php). – the.marolie Apr 25 '19 at 09:58
  • 3
    This is a bit too broad for SO's simple Q/A format, you really need a full blown tutorial on [maintaining application state with sessions in PHP](http://www.devshed.com/c/a/php/introduction-to-maintaining-the-state-of-applications-with-php-sessions/) (*<-- for example, from a quick search*). – CD001 Apr 25 '19 at 10:07

1 Answers1

0

In your loginn.php page. at the top of the page start the session. like

session_start();//this

then search input Mobile_No and input Password in your data base if found then assign session variable user_id like

$_SESSION['user_id'] = $user->ID;

note: if any page already have session_start(); function then write ob_start(); function.

treyBake
  • 6,440
  • 6
  • 26
  • 57
MH Fuad
  • 746
  • 6
  • 16