Webbserverprogrammering 1

Show sourcecode

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

webbserverprogrammering/projekt/snake_oil_seller/php/

about_us.php
admin.php
contact.php
create_products.php
create_tables.php
createtable.php
dbconnection.php
delete_post.php
delete_tables.php
deletepost.php
deletetable.php
entry.php
header.php
insert_posts.php
insertposts.php
leaderboard.php
log_in.php
log_out.php
main.php
my_account.php
question_maker.php
quiz_form.php
quiz_list.php
quiz_maker.php
result.php
select_posts.php
selectposts.php
shop.php
shop_item.php
shopping_cart.php
sign_in.php
title_card.php
update_posts.php
updateposts.php
user_verified.php
verify_page.php

sign_in.php

100 lines UTF-8 Windows (CRLF)
<!-- insertpost.php -->
<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <title>Sign in</title>
  </head>
  <link href="../css/snake_oil.css" rel="stylesheet">
  <link href="../css/log-sign_in.css" rel="stylesheet"> 
<body>
  <?php
    
include ('dbconnection.php');
    
$message null;
    if (isset(
$_POST['username']) && isset($_POST['password']) && !empty($_POST['username']) && !empty($_POST['password'])) {
        
        
// Hämtar användarnamn och lösenord från formuläret
        
$username $_POST['username'];
        
$email $_POST['username'];
        
$password $_POST['password'];

        
// Förbereder frågan till databasen
        
$stmt $dbconn->prepare("SELECT username FROM users WHERE username = ?");
        
$stmt->execute([$username]);
        
$user $stmt->fetch(PDO::FETCH_ASSOC);

        
// Kollar om användaren finns i databasen
        
if ($user){
          
// Användaren finns
          
echo "En användare med samma namn finns redan";
        } else {
          
// Användaren finns inte, skickas till quiz listan
          
try {
            
// Hashar lösenordet
            
$hash password_hash($passwordPASSWORD_DEFAULT);
            
# prepare
            
$sql "INSERT INTO users (username, email, password, is_verified, reg_date) 
              VALUES (?, ?, ?, ?, now())"
;
            
$stmt $dbconn->prepare($sql);
            
# the data we want to inser
            
$data = array($usernamenull$hash"no");
            
# execute width array-parameter
            
$stmt->execute($data);
                
            
// Nytt konto tillagt
            
$lastId $dbconn->lastInsertId();

            
session_start();

            
$_SESSION["username"] = $username;
            
$_SESSION["email"] = $email;
            
$_SESSION["usertype"] = "user";
          }
          catch(
PDOException $e)
              {
              echo 
$sql "<br>" $e->getMessage();
          }
          
$dbconn null;
          
          
header("Location: verify_page.php");
        }

    } else {
        
$message .= "";

    }
    echo 
$message;
  
?>
  <!-- Titel -->
  <?php include "title_card.php";?>

    <!-- Skapa Konto Ruta --> 
    <main>
      <h2><strong>Skapa konto:</strong></h2>
      <form method="post" action="" id="form"> 
        <table> 
          <tr>
            <td><span style="display:flex; justify-content: right;">Användarnamn*:</span></td>
            <td><input type="text" name="username" size=40 maxlength=100 placeholder="Kristian Tyrann"></td>
          </tr>
          <tr>
            <td><span style="display:flex; justify-content: right;">Lösenord*:</span></td>
            <td><input type="password" name="password" size=40 maxlength=100 placeholder="XxRIPTheGoatxX"></td>
          </tr>
          <tr>
            <td><span style="display:flex; justify-content: right;">* = obligatoriskt:</span></td>
            <td><button type="submit">Lägg till konto</button></td>
          </tr>
        </table>
      </form>
    </main>
    <!--Tillbaka-->
    <div id="exit_div">
      <h4>Tillbaka</h4>
      <span>
        <a href="log_out.php">Startsida</a>
        <a href="log_in.php">Logga in</a>
      </span>
    </div>
  </body>
</html>