Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

login form using php pdo

include './database/PDO.php';

$sendmessage = null;
$Message = null;

if (isset($_POST['enter'])){
    $email = $_POST['email'];
    $password = $_POST['password'];
    $result = $conn-> prepare("SELECT * FROM sign WHERE email=? AND password=?");
    $result->bindValue(1, $email);
    $result->bindValue(2, $password);
    $result->execute();
    header('location: ./dashboard.php');
    $sendmessage = true;

    if($result->rowCount()>=1){
        $rows = $result->fetch(PDO::FETCH_ASSOC);
        $_SESSION['login']= true;
        $_SESSION['email']= $email;
        $_SESSION['password']= $password;
        $_SESSION['role']= $rows['role'];
        if(isset($_POST['rem'])){
            setcookie('email', $SESSION['email'], time()+60*60*24*7, '/');
            setcookie('password', $SESSION['password'], time()+60*60*24*7, '/');

        }else{
            echo $Message= true;
        }

    }else{
        echo $Message= true;
    }
}
?>
  <form class="row g-3 needs-validation" method="POST" novalidate>
                <label for="validationCustom02" class="form-label">ایمیل</label>
                <input type="email" name="email" class="form-control" id="validationCustom02"
                       required>
                <div class="invalid-feedback">
                    <div class="alert alert-danger" role="alert">
                        لطفا فیلد ایمیل را پر کنید

                    </div>
                </div>

                <label for="validationCustom02" class="form-label">نام کاربری شما</label>
                <input type="text" name="username" class="form-control" id="validationCustom02"
                       required>
                <div class="invalid-feedback">
                    <div class="alert alert-danger" role="alert">
                        لطفا فیلد نام کاربری را پر کنید

                    </div>
                </div>
                <label for="validationCustom02" class="form-label">رمز عبور </label>
                <input type="password" class="form-control" id="validationCustom02" name="password" required>
                <div class="invalid-feedback">
                    <div class="alert alert-danger" role="alert">
                        لطفا فیلد پسورد را پر کنید

                    </div>
                </div>
                <input type="checkbox" name="rem" class="form-check-input mt-3">
                <label class="form-label" style="margin-right: 50px;margin-top: -20px;">مرا به خاطر بسپار</label>
                <input type="submit" value="ورود" class="btn btn-primary" name="enter">

            </form>
Source by laracasts.com #
 
PREVIOUS NEXT
Tagged: #login #form #php #pdo
ADD COMMENT
Topic
Name
7+9 =