Webbserv1: Källkod
Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/projects/slutprojekt/

blala.php
chat.php
createtable.php
delete.php
deletetable.php
deletetables.php
fetch_messages.php
filhantering/
footer.php
header.php
home.php
login.php
new_password.php
password_reset.php
profile.php
send_message.php
signup.php
verify.php

password_reset.php

59 lines UTF-8 Windows (CRLF)
<?php
session_start
();
?>
<!doctype html>
<html>

<body>
<?php
include ('../../dbconnection.php');
$message null;
  if (isset(
$_POST['email']) && !empty($_POST['email'])) {
    
$email htmlentities($_POST['email']);
    
$token bin2hex(random_bytes(16));

    
$_SESSION['reset_token'] = $token;
    
$_SESSION['reset_token_expiry'] = time() + 900;
    
    try {    
      
$sql "SELECT COUNT(*) FROM webusers WHERE email = ?";
      
$stmt $dbconn->prepare($sql);
      
$stmt->execute([$email]);

      
$result $stmt->fetchColumn();

      if (
$result 0) {
        
$verify_link "https://labb.vgy.se/~noahet/webbsrvprg/projects/slutprojekt/new_password.php?email=" urlencode($email) . "&token=" $token;

        
$headers "From: no-reply@banan.com";
        
$subject "Verifiera din e-postadress";
        
$message "Klicka på länken för att verifiera din e-post: $verify_link";
        
mail($email$subject$message$headers);
        echo 
"mejl skickat";
      } else {
        echo 
"E-postadressen finns ej";
      }

        
$lastId $dbconn->lastInsertId();
    }
    catch(
PDOException $e)  {
        echo 
$sql "<br>" $e->getMessage();
    }
    
    
$dbconn null;
  } else {
    
$message .= "<br />Du måste fylla i fälten!<br /><br />";
  }
echo 
$message;
?>
<form method="post" action="" enctype="multipart/form-data"> 

  Epost:
  <input type="email" name="email" size=40 maxlength=100 required><br><br>

  <button type="submit">Skicka mejl</button><br><br>

  <a href="login.php">Till inloggningssida</a>
</form>
</body>
</html>