Webbserverprogrammering 1

Show sourcecode

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

webbserverprogrammering/projekt/snake_oil_seller/php/

about_us.php
add_to_cart.php
admin.php
buy_cart.php
config.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

header.php

273 lines UTF-8 Windows (CRLF)
<?php
  
/** @var PDO $dbconn*/
  
include ("dbconnection.php");

  
// Kollar och ändrar vald flik beroende på vald sida
  
$currentPage basename($_SERVER["PHP_SELF"]);

  
// Kollar om man är admin för att visa "create_products
  
if ($is_logged_in) {
    
$sql $dbconn->prepare("SELECT usertype FROM users WHERE username = ?");
    
$sql->execute([$_SESSION["username"]]);

    
$result $sql->fetch(PDO::FETCH_ASSOC);

    if (
$result["usertype"] == "admin") {
      
$is_admin true;
    } else {
      
$is_admin false;
  }
  }

  if (
$is_logged_in && $is_admin) {
    
// Inloggad - "My account" länken finns
    
if ($currentPage === "main.php") {
      echo 
'
      <div id="rubrics">
        <a href="main.php"style="font-weight: bold; font-size: 1.5em;">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="my_account.php">My account</a>
        <a href="create_products.php">Create products</a>
        <a href="log_out.php">Log out</a>
      </div>'
;

    } else if (
$currentPage === 'shop.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php" style="font-weight: bold;  font-size: 1.5em;">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="my_account.php">My account</a>
        <a href="create_products.php">Create products</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'about_us.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php" style="font-weight: bold; font-size: 1.5em;">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="my_account.php">My account</a>
        <a href="create_products.php">Create products</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'contact.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php" style="font-weight: bold; font-size: 1.5em;">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="my_account.php">My account</a>
        <a href="create_products.php">Create products</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'shopping_cart.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php" style="font-weight: bold; font-size: 1.5em;">Shopping cart</a>
        <a href="my_account.php">My account</a>
        <a href="create_products.php">Create products</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'my_account.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="my_account.php" style="font-weight: bold; font-size: 1.5em;">My account</a>
        <a href="create_products.php">Create products</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'shop_item.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="my_account.php"">My account</a>
        <a href="create_products.php">Create products</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    }
  } else if (
$is_logged_in && !$is_admin) {
    
// Inloggad med vanlig user
    
if ($currentPage === "main.php") {
      echo 
'
      <div id="rubrics">
        <a href="main.php"style="font-weight: bold; font-size: 1.5em;">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="my_account.php">My account</a>
        <a href="log_out.php">Log out</a>
      </div>'
;

    } else if (
$currentPage === 'shop.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php" style="font-weight: bold;  font-size: 1.5em;">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="my_account.php">My account</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'about_us.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php" style="font-weight: bold; font-size: 1.5em;">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="my_account.php">My account</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'contact.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php" style="font-weight: bold; font-size: 1.5em;">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="my_account.php">My account</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'shopping_cart.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php" style="font-weight: bold; font-size: 1.5em;">Shopping cart</a>
        <a href="my_account.php">My account</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'my_account.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="log_in.php">Log in</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'shop_item.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="my_account.php">My account</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    }
  } else {
    
// Inte inloggad - My account blir till "log in"
    
if ($currentPage === "main.php") {
      echo 
'
      <div id="rubrics">
        <a href="main.php"style="font-weight: bold; font-size: 1.5em;">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="log_in.php">Log in</a>
        <a href="log_out.php">Log out</a>
      </div>'
;

    } else if (
$currentPage === 'shop.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php" style="font-weight: bold;  font-size: 1.5em;">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="log_in.php">Log in</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'about_us.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php" style="font-weight: bold; font-size: 1.5em;">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="log_in.php">Log in</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'contact.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php" style="font-weight: bold; font-size: 1.5em;">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="log_in.php">Log in</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'shopping_cart.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php" style="font-weight: bold; font-size: 1.5em;">Shopping cart</a>
        <a href="log_in.php">Log in</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'my_account.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="log_in.php" style="font-weight: bold; font-size: 1.5em;">Log in</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    } else if (
$currentPage === 'shop_item.php') {
      echo 
'
      <div id="rubrics">
        <a href="main.php">Main</a>
        <a href="shop.php">Shop</a>
        <a href="about_us.php">About us</a>
        <a href="contact.php">Contact</a>
        <a href="shopping_cart.php">Shopping cart</a>
        <a href="log_in.php">Log in</a>
        <a href="log_out.php">Log out</a>
      </div>'
;
    }
  }
?>