Advertisement
tadejpetric

Untitled

Mar 15th, 2018
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.15 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. $conn = new mysqli("localhost", "root", "", "abcd"); //"baza.nekaj.si", "root", "root", "abcd");
  5. if($conn->connect_error)
  6.     die("fail". $conn->connect_error);
  7.  
  8. $conn->set_charset("UTF-8");
  9.  
  10. if (!isset($_SESSION["cnt"]))
  11.     $_SESSION["cnt"] = 0;
  12. if (!isset($_SESSION["logged"]))
  13.     $_SESSION["logged"] = FALSE;
  14.  
  15. if (isset($_GET["submit"]) && $_SESSION["logged"] == FALSE) {
  16.     $sql = "SELECT uporabnik, geslo, statusUporabnika, id FROM uporabnik WHERE uporabnik = '". $_GET["username"]. "' AND geslo = '" . $_GET["password"] ."';";
  17.     $result = $conn->query($sql);
  18.     echo $conn->error;
  19.     if($result->num_rows == 0) {
  20.         $_SESSION["cnt"]++;
  21.     }
  22.     else {
  23.         $row = $result->fetch_assoc();
  24.         $sql = "UPDATE uporabnik SET datumZadnjegaDostopa = ". date("Y-m-d") ." WHERE id = ".$row["id"].";";
  25.         $_SESSION["logged"] = TRUE;
  26.         logged($row["statusUporabnika"]);
  27.     }
  28. }
  29. if (isset($_GET["delete"])) {
  30.     $sql = "DELETE FROM uporabnik WHERE id = ". $_GET["cbox"].";";
  31.     $conn->query($sql);
  32. }
  33.  
  34. if($_SESSION["cnt"] > 3) {
  35.     header("Location: www.yahoo.com");
  36.     die();
  37. }
  38.  
  39. if ($_SESSION["logged"]==FALSE) {
  40.     echo '<form>
  41.    uporabnisko ime <input type="text" name="username"><br>
  42.    password <input type="password" name="password"><br>
  43.    <input type="submit" name="submit" value="submit">
  44.    </form>';
  45. }
  46.  
  47. function logged($state) {
  48.     global $conn;
  49.     $sql = "SELECT uporabnik, id, datumZadnjegaDostopa FROM uporabnik;";
  50.     $result = $conn->query($sql);
  51.  
  52.     echo "<form><table>";
  53.     if ($result->num_rows > 0) {
  54.         while($row = $result->fetch_assoc()) {
  55.             echo "<tr>";
  56.             echo "<td>". $row["uporabnik"]."</td><td>".$row["datumZadnjegaDostopa"]."</td>";
  57.             if(strtotime($row["datumZadnjegaDostopa"]) < strtotime("-30 days"))
  58.                 if($state == "upravitelj")
  59.                     echo '<td><input type="radio" name="cbox" value="'.$row["id"].'"></td>';
  60.             echo "</tr>";
  61.         }
  62.     }
  63.     if ($state == "upravitelj")
  64.         echo '<input type="submit" name="delete" value="delete">';
  65.     echo "</table></form>";
  66. }
  67. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement