Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Maak een include folder aan.
- 2. Maak een PHP bestand aan met de naam dbh.inc.php en zet daar de volgende code in
- <?php
- $servername = "localhost";
- $dBUSername = "root";
- $dBPassword = "";
- $dBName = "mddatabase";
- $conn = mysqli_connect($servername, $dBUSername, $dBPassword, $dBName);
- if(!conn){
- die("<script>console.log('Connection has failed:". mysqli_connect_error ."')</script>" );
- }
- 3. Maak een file aan met de naam login.inc.php
- 4. Zet daar de volgende code in.
- <?php
- if(isset($_POST['login-verzenden'])){
- require 'dbh.inc.php';
- $email = $_POST['Email'];
- $wachtwoord = $_POST['Wachtwoord'];
- if (empty($email) || empty($wachtwoord)){
- header("Location: ../index.php?error=emptyfields");
- exit();
- } else {
- $sql = "SELECT * FROM werknemers WHERE Naam=? OR Email=?;" ;
- $stmt = mysqli_stmt_init($conn);
- if (!mysqli_stmt_prepare($stmt, $sql)){
- header("Location: ../index.php?error=sqlerror");
- exit();
- } else {
- mysqli_stmt_bind_param($stmt, "ss", $email, $email);
- mysqli_stmt_execute($stmt);
- $result = mysqli_stmt_get_result($stmt);
- if ($row = mysqli_fetch_assoc($result)){
- $wachtwoordcheck = password_verify($wachtwoord, $row['Wachtwoord']);
- if ($wachtwoordcheck == false) {
- header("Location: ../index.php?wrongpassword");
- exit();
- }else if($wachtwoordcheck == true){
- session_start();
- $_SESSION['NaamId'] = $row['WID'];
- $_SESSION['Werknemer'] = $row['Naam'];
- $_SESSION['Beroepsfunctie'] = $row['Functie'];
- header("Location: ../index.php?login=Succes");
- exit();
- }
- }else{
- header("Location: ../index.php?noUser");
- exit();
- }
- }
- }
- } else {
- header("Location: ../index.php");
- exit();
- }
- 5. Maak een nieuwe file aan met de naam logout.inc.php
- 6. zet daar de volgende code in.
- <?php
- session_start();
- session_unset();
- session_destroy();
- header("Location: ../index.php");
- 7. Maak een nieuwe file aan met de naam
- <?php
- if (isset($_POST['registratie-verzenden'])) {
- require 'dbh.inc.php';
- $username = $_POST['Gebruikersnaam'];
- $email = $_POST['Email'];
- $functie = $_POST['Functie'];
- $wachtwoord = $_POST['Wachtwoord'];
- $wachtwoordHerhalen = $_POST['WachtwoordHerhalen'];
- if (empty($username) || empty($email) || empty($functie) || empty($wachtwoord) || empty($wachtwoordHerhalen)) {
- header("Location: ../registreer.php?error=Emptyfields&Email=" . $email . "&Functie=" . $functie . "&Gebruikersnaam=" . $username);
- exit();
- } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL) && !preg_match("/^[a-zA-Z0-9]*$/", $username)) {
- header("Location: ../registreer.php?error=invalidUser");
- exit();
- } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
- header("Location: ../registreer.php?error=invalidmail&Gebruikersnaam=" . $username . "&Functie=" . $functie);
- exit();
- } elseif (!preg_match("/^[a-zA-Z0-9]*$/", $username)) {
- header("Location: ../registreer.php?error=invalidUserChar&Email=" . $email . "&Functie=" . $functie);
- exit();
- } elseif ($wachtwoord !== $wachtwoordHerhalen) {
- header("Location: ../registreer.php?error=invalidPWDMatch&Email=" . $email . "&Functie=" . $functie . "&Gebruikersnaam=" . $username);
- } else {
- $sql = "SELECT Naam FROM werknemers WHERE Naam=?";
- $stmt = mysqli_stmt_init($conn);
- if (!mysqli_stmt_prepare($stmt, $sql)) {
- header("Location: ../registreer.php?error=sqlerrorUserEX");
- exit();
- } else {
- mysqli_stmt_bind_param($stmt, "s", $username);
- mysqli_stmt_execute($stmt);
- mysqli_stmt_store_result($stmt);
- $resultCheck = mysqli_stmt_num_rows($stmt);
- if ($resultCheck > 0) {
- header("Location: ../registreer.php?error=gebruikerbestaatal&Email=" . $email);
- exit();
- } else {
- $sql = "INSERT INTO werknemers (Naam, Email, Functie, Wachtwoord) VALUES (?, ?, ?, ?)";
- $stmt = mysqli_stmt_init($conn);
- if (!mysqli_stmt_prepare($stmt, $sql)) {
- header("Location: ../registreer.php?error=sqlerror");
- exit();
- } else {
- $hashedWW = password_hash($wachtwoord, PASSWORD_DEFAULT);
- mysqli_stmt_bind_param($stmt, "ssss", $username, $email, $functie, $hashedWW);
- mysqli_stmt_execute($stmt);
- header("Location: ../registreer.php?registratie=succes");
- exit();
- }
- }
- }
- }
- mysqli_stmt_close($stmt);
- mysqli_close($conn);
- } else {
- header("Location: ../registreer.php");
- exit();
- }
- 8. Als laatste zet je deze code in je header.php file.
- <?php
- if(isset($_SESSION['Werknemer'])){
- $Welkombericht = "<div class='WelkomBericht'>"."Welkom: " . $_SESSION['Werknemer'] . "</div>";
- echo $Welkombericht;
- }?></li>
- <div class="forminput">
- <?php
- if(isset($_SESSION['Werknemer'])){
- echo '<form class="fomr-inline" action="includes/logout.inc.php" method="post">
- <button type="submit" name="loguit-verzenden">Uitloggen <i class="fas fa-sign-in-alt"></i></button>
- </form>';
- } else {
- echo
- '<form action="includes/login.inc.php" method="post">
- <input type="text" name="Email"autocomplete="off" placeholder="Gebruikersnaam / E-mail...">
- <input type="password" name="Wachtwoord" placeholder="Wachtwoord...">
- <button type="submit" name="login-verzenden">Inloggen <i class="fas fa-sign-in-alt"></i></button>
- <a href="registreer.php">Registreer</a>
- </form>';
- }
- ?>
- 9. ook zet je deze php code boven aan de pagina
- <?php
- session_start();
- ?>
- <?php echo $title;?>
- 10. als laatste zet je in de header de glyphicon link in de head
- <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
- </head>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement