Advertisement
mrkure

Untitled

Jun 27th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.24 KB | None | 0 0
  1. //////////////////////////////////loginpost.php////////////////////////////////////////////////
  2.  
  3. <?php
  4.  
  5. session_start();
  6.  
  7. if (isset($_POST['submit'])) {
  8.    
  9.     include 'connect.php';
  10.  
  11.     $usrn = mysqli_real_escape_string($conn, $_POST['uname']);
  12.     $pasw = mysqli_real_escape_string($conn, $_POST['upassword']);
  13.  
  14.     //check if inputs are empty
  15.     if (empty($usrn) || empty($pasw)) {
  16.         header("Location: index.php?login=empty");
  17.         exit();
  18.     } else{
  19.         $sql = "SELECT * FROM users WHERE username = '$usrn'";
  20.         $result = mysqli_query($conn, $sql);
  21.         $resultcheck = mysqli_num_rows($result);
  22.         if ($resultcheck < 1){
  23.             header("Location: index.php?login=error");
  24.             exit();
  25.         } else {
  26.             if ($row = mysqli_fetch_assoc($result)) {
  27.                 //de-hasing wachtwoord
  28.                 $hashedpwdcheck = password_verify($pasw, $row['password']);
  29.                 if ($hashedpwdcheck == false) {
  30.                     header("Location: index.php?login=pwerror");
  31.                     exit();
  32.                 } elseif ($hashedpwdcheck == true) {
  33.                     //Log in the user here
  34.                     $_SESSION['u_id'] = $row['user_id'];
  35.                     $_SESSION['u_username'] = $row['username'];
  36.                     $_SESSION['u_pw'] = $row['password'];
  37.                     $_SESSION['u_name'] = $row['naam'];
  38.                     $_SESSION['u_adres'] = $row['adres'];
  39.                     $_SESSION['u_admin'] = $row['admin'];
  40.                     header("Location: index.php?login=success");
  41.                     exit();
  42.  
  43.                 }
  44.             }
  45.         }
  46.     }
  47. } else {
  48.     header("Location: index.php?login=error");
  49.     exit();
  50. }
  51. ?>
  52.  
  53.  
  54. //////////////////////////////////////////////////logout.php//////////////////////////////////////
  55.  
  56. <?php
  57.  
  58.  
  59.  
  60. if (isset($_POST['submit'])) {
  61.     session_start();
  62.     session_unset();
  63.     session_destroy();
  64.     header("Location: index.php");
  65.     exit();
  66. }
  67.  
  68.  
  69. /////////////////////////////////////////////////register.php/////////////////////////////////////////////
  70.  
  71.  
  72. <?php
  73.     include_once 'header.php';
  74. ?>
  75.  
  76.  
  77. <section>
  78.  
  79. <div class="container">
  80.     <form class="form-horizontal" action="/registerpost.php" method="POST">
  81.  
  82.     <div class="panel panel-warning">
  83.         <div class="panel-heading">Registeren</div>
  84.             <div class="panel-body">
  85.                 <label class="col-sm-2 control-label"><b>Gebruikersnaam</b></label>
  86.                 <div class="col-sm-10">
  87.                     <input type="text" class="form-control" placeholder="gebruikersnaam" name="username" required>
  88.                     </br>
  89.                 </div>
  90.                 <label class="col-sm-2 control-label"><b>Wachtwoord</b></label>
  91.                 <div class="col-sm-10">
  92.                     <input type="password" class="form-control" placeholder="wachtwoord" name="password" required>
  93.                     </br>
  94.                 </div>
  95.                 </br>
  96.                 <label class="col-sm-2 control-label"><b>Naam</b></label>
  97.                 <div class="col-sm-10">
  98.                     <input type="text" class="form-control" placeholder="Naam" name="naam" required>
  99.                     </br>
  100.                 </div>
  101.                 <label class="col-sm-2 control-label"><b>Adres</b></label>
  102.                 <div class="col-sm-10">
  103.                     <input type="text" class="form-control" placeholder="Adres" name="adres" >
  104.                     </br>
  105.                 </div>
  106.                 <div class="btn-group col-sm-offset-2 col-sm-10" role="group">
  107.                   <button type="button"  class="btn btn-danger" name="cancel">Cancel</button>
  108.                   <button type="submit" class="btn btn-primary" name="submit">Sign Up</button>
  109.                 </div>
  110.             </div>
  111.     </div>
  112.     </form>
  113. </div>
  114. </section>
  115.  
  116. <?php
  117.     include_once 'footer.php';
  118. ?>
  119.  
  120.  
  121. /////////////////////////////////////////////////////header.php//////////////////////////////////////////////
  122.  
  123.  
  124.  
  125. <?php
  126.  
  127. session_start();
  128.  
  129. ?>
  130.  
  131.  
  132. <!DOCTYPE html>
  133. <html>
  134. <head>
  135. <title>
  136. </title>
  137. <!-- Latest compiled and minified CSS -->
  138. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  139.  
  140. <!-- Optional theme -->
  141. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
  142.  
  143. <!-- Latest compiled and minified JavaScript -->
  144. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  145. </head>
  146.  
  147. <body>
  148.  
  149.  
  150. <nav class="navbar navbar-default">
  151.   <div class="container-fluid">
  152.     <div class="navbar-header">
  153.         <a class="navbar-brand" href="index.php">Home</a>
  154.  
  155.                     <div class="navbar-left">
  156.                         <?php
  157.                             if (isset($_SESSION['u_id'])) {
  158.                                 if ($_SESSION['u_admin']) {
  159.                                     echo '<ul class="nav navbar-nav">
  160.                                     <li><a href="verhuurd.php">Verhuurd autos</a></li>
  161.                                     </ul>
  162.                                     <form class="navbar-form navbar-left" action="logout.php" method="POST">
  163.                                     <button type="submit" class="btn btn-danger" name="submit">Logout</button>
  164.                                     </form>';
  165.                                 }
  166.                                 if (!$_SESSION['u_admin']) {
  167.                                     echo '<ul class="nav navbar-nav">
  168.                                     <li><a href="autohuren.php">Auto huren</a></li>
  169.                                     </ul>
  170.                                     <form class="navbar-form navbar-left" action="logout.php" method="POST">
  171.                                     <button type="submit" class="btn btn-danger" name="submit">Logout</button>
  172.                                     </form>';
  173.                                 }
  174.                             } else {
  175.                                 echo '<form class="navbar-form navbar-left" action="/loginpost.php" method="POST">
  176.                                 <div class="form-group">           
  177.                                   <input type="text" class="form-control" placeholder="gebruikersnaam" name="uname" required>
  178.                                   <input type="password" class="form-control" placeholder="wachtwoord" name="upassword" required>
  179.                                  </div>
  180.                                   <button type="submit" class="btn btn-default" name="submit">Login</button>
  181.  
  182.                                    
  183.                                 </form>
  184.                                 <ul class="nav navbar-nav">
  185.                                     <li><a href="register.php">Registeren</a></li>
  186.                                 </ul>';
  187.                             }
  188.  
  189.                         ?>
  190.  
  191.  
  192.                     </div>
  193.         </div>
  194.         </div>
  195. </nav>
  196.  
  197.  
  198. /////////////////////////////////////////////////////////autohuren.php///////////////////////////////////////////////////
  199.  
  200.  
  201. <?php
  202.     include_once 'header.php';
  203. ?>
  204.  
  205. <div class="container">
  206.      <div class="panel panel-warning">
  207.         <div class="panel-heading">Auto huren</div>
  208.             <div class="panel-body">
  209. <?php
  210.  
  211. include 'connect.php';
  212.  
  213. $sql = "SELECT * from auto WHERE status = 0";
  214. $res = mysqli_query($conn, $sql);
  215. while ($list2 = mysqli_fetch_assoc($res)){
  216.     $kenteken = $list2['kenteken'];
  217.     $merk = $list2['merk'];
  218.     $type = $list2['type'];
  219.     $price = $list2['dagprijs'];
  220. ?>
  221.  
  222.     <ul>
  223.     <li><?php echo $kenteken;?></li>
  224.     <li><?php echo $merk; ?></li>
  225.     <li><?php echo $type; ?></li>
  226.     <li>&euro;<?php echo $price; ?> Per dag</li>
  227.     </ul>
  228. <?php
  229. }
  230. ?>
  231.  
  232. <form action="/hurenaction.php" method="POST">
  233. <label class="control-label"><b>Begindatum</b></label>
  234. <input type="text" class="form-control" placeholder="jaar-maand-dag" name="begindatum" required>
  235. <label class="control-label"><b>Einddatum</b></label>
  236. <input type="text" class="form-control" placeholder="jaar-maand-dag" name="einddatum" required>
  237. </p>
  238.  
  239.  
  240. <select name="autoselect">
  241. <?php
  242. $sql2 = "SELECT * from auto WHERE status = 0";
  243. $res2 = mysqli_query($conn, $sql);
  244.  
  245. while($list = mysqli_fetch_assoc($res2)):; ?>
  246.  
  247. <option value="<?php echo $list['kenteken']; ?>"><?php echo $list['kenteken']; ?></option>
  248. <?php endwhile; ?>
  249. </select>
  250. </p>
  251. <button type="submit" class="btn btn-primary" name="submit">Submit</button>
  252. </form>
  253. </div>
  254. </div>
  255. </div>
  256. </div>
  257.  
  258.  
  259. <?php
  260.     include_once 'footer.php';
  261. ?>
  262.  
  263.  
  264.  
  265. ////////////////////////////////////////////////////////hurenaction.php//////////////////////////////////////////
  266.  
  267.  
  268.  
  269. <?php
  270.  
  271. session_start();
  272.  
  273. if (isset($_POST['submit'])) {
  274.     include_once 'connect.php';
  275.  
  276.     $kenteken = mysqli_real_escape_string($conn, $_POST['autoselect']);
  277.     $userid = $_SESSION['u_username'];
  278.     $startdate = mysqli_real_escape_string($conn, $_POST['begindatum']);
  279.     $enddate = mysqli_real_escape_string($conn, $_POST['einddatum']);
  280.  
  281.     //Error hanlers
  282.     // Check for empty fields
  283.     if (!preg_match("/^[a-zA-Z]*$/", $userid)){
  284.         header("Location: autohuren.php?huren=invalid");
  285.     } else {
  286.             //insert data in de database
  287.             $sql= "INSERT INTO factuur (factuurnummer, factuurdatum, kenteken, user_name, begindatum, einddatum) VALUES (NULL, NOW(), '$kenteken', '$userid', '$startdate', '$enddate');";
  288.             $sql2 = "UPDATE auto SET status = 1 WHERE '$kenteken' = kenteken";
  289.             mysqli_query($conn, $sql);
  290.             mysqli_query($conn, $sql2);
  291.             header("Location: autohuren.php?signup=success");
  292.             exit();
  293.         }
  294.  
  295.  
  296. } else {
  297.     header("Location: autohuren.php");
  298.     exit();
  299. }
  300.  
  301.  
  302.  
  303. ///////////////////////////////////////////////////////registerpost.php/////////////////////////////////////////////
  304.  
  305.  
  306. <?php
  307.  
  308.  
  309. if (isset($_POST['submit'])) {
  310.     include_once 'connect.php';
  311.  
  312.     $usrn = mysqli_real_escape_string($conn, $_POST['username']);
  313.     $pasw = mysqli_real_escape_string($conn, $_POST['password']);
  314.     $name = mysqli_real_escape_string($conn, $_POST['naam']);
  315.     $adre = mysqli_real_escape_string($conn, $_POST['adres']);
  316.  
  317.     //Error hanlers
  318.     // Check for empty fields
  319.     if (!preg_match("/^[a-zA-Z]*$/", $name)){
  320.         header("Location: register.php?signup=invalid");
  321.     } else {
  322.         $sql = "SELECT * FROM users WHERE username='$usrn'";
  323.         $result = mysqli_query($conn, $sql);
  324.         $resultcheck = mysqli_num_rows($result);
  325.  
  326.         if($resultcheck > 0){
  327.             header("Location: register.php?signup=usertaken");
  328.             exit();
  329.         } else {
  330.             //hashing password//
  331.             $hashedpasw = password_hash($pasw, PASSWORD_DEFAULT);
  332.             //insert gebruikerin de database
  333.             $sql= "INSERT INTO users (username, password, naam, adres) VALUES ('$usrn', '$hashedpasw', '$name', '$adre');";
  334.             mysqli_query($conn, $sql);
  335.             header("Location: register.php?signup=success");
  336.             exit();
  337.         }
  338.     }
  339.  
  340. } else {
  341.     header("Location: register.php");
  342.     exit();
  343. }
  344.  
  345.  
  346.  
  347. ?>
  348.  
  349.  
  350. /////////////////////////////////////////////////////footer.php///////////////////////////////////////////////////
  351.  
  352. </body>
  353. </html>
  354.  
  355.  
  356.  
  357. ///////////////////////////////////////////////////index.php////////////////////////////////////////////////////////
  358.  
  359.  
  360. <?php
  361.     include_once 'header.php';
  362. ?>
  363.  
  364. <section>
  365.     <div class="container">
  366.         <h2>Welcome to Rent-a-Car</h2>
  367.         <?php
  368.         if (isset($_SESSION['u_id'])) {
  369.  
  370.             if (!$_SESSION['u_admin']) {
  371.                 echo "<h4>Gebruiker ".$_SESSION['u_username']. "</h4>";
  372.             } elseif ($_SESSION['u_admin']){
  373.                 echo "<h4>Medewerker ".$_SESSION['u_username']. "</h4>";
  374.             }
  375.         }
  376.         ?>
  377.     </div>
  378.  
  379. <?php
  380.     include_once 'footer.php';
  381. ?>
  382.  
  383.  
  384. ///////////////////////////////////////////////////////////connect.php////////////////////////////////////////////////
  385.  
  386.  
  387. <?php
  388.  
  389. $dbServername ="localhost";
  390. $dbUsername = "root";
  391. $dbPassword="";
  392. $dbName = "mywebsite";
  393.  
  394. $conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
  395.  
  396. ?>
  397.  
  398.  
  399.  
  400. /////////////////////////////////////////////////////////verhuurd.php//////////////////////////////////////////////////
  401.  
  402.  
  403. <?php
  404.     include_once 'header.php';
  405. ?>
  406.  
  407. <div class="container">
  408.     <div class="panel panel-primary">
  409.         <div class="panel-heading"></br></p></div>
  410.             <div class="panel-body">
  411. <?php
  412.  
  413. include 'connect.php';
  414.  
  415. $sql = "SELECT * FROM auto WHERE status = 1 ";
  416. $res = mysqli_query($conn, $sql);
  417.  
  418.  
  419. while($row = mysqli_fetch_assoc($res)){
  420.         echo  "<h2>Verhuud auto's</h2></p><b>Kenteken:  </b>".$row['kenteken'].'</br><b>Merk: </b> ' .$row['merk'].'</br><b>Auto type:  </b>' .$row['type'].'</br><b>Huurprijs per dag: </b> &euro;' .$row['dagprijs'].'</br>' ;
  421.         $sql2 = "SELECT * FROM factuur WHERE kenteken = '".$row['kenteken']."'";
  422.         $res2 = mysqli_query($conn, $sql2);
  423.         if($row2 = mysqli_fetch_array($res2)){
  424.             echo  '<b>Factuurdatum:</b>  '.$row2['factuurdatum'].'</br><b>Naam huurder:</b>  ' .$row2['user_name'].'</br><b>Begindatum:</b>  ' .$row2['begindatum'].'</br><b>Einddatum:</b>  ' .$row2['einddatum'].'</p>' ;
  425.         }
  426.  
  427. }
  428.  
  429.  
  430. ?>
  431.  
  432.  
  433. <input type="button" value="Print" onclick="javascript: window.print();">
  434.  
  435. </div>
  436. </div>
  437. </div>
  438.  
  439. <?php
  440.     include_once 'footer.php';
  441. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement