Advertisement
Guest User

Untitled

a guest
May 15th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.25 KB | None | 0 0
  1. <?php
  2. session_start();
  3. function printNews($db)
  4. {
  5.     $query = 'select * from kfs_news;';
  6.     $result = $db->query($query);
  7.     while ($row = $result->fetch_assoc())
  8.     {
  9.         $content = $row['content'];
  10.         $author = $row['author'];
  11.         $date = $row['date'];
  12.         echo("<li>$content <b>($date av <i>$author</i>)</b><br />Delete this post</li>\n");
  13.     }
  14. }
  15.  
  16. if (isset($_POST['password']))
  17. {
  18.     $password = hash('sha256', $_POST['password']);
  19.     $sql_host = '**********';
  20.     $sql_user = '**********';
  21.     $sql_pass = '**********';
  22.     $sql_db   = '**********';
  23.     $db = new mysqli($sql_host, $sql_user, $sql_pass, $sql_db);
  24.  
  25.     $query = 'select pass_sha256 from kfs_logon where user = "generic_newspost"';
  26.     $result = $db->query($query);
  27.     $row = $result->fetch_assoc();
  28.     $passCompare = $row['pass_sha256'];
  29.    
  30.     if ($password == $passCompare)
  31.     {
  32.         $_SESSION['loggedin'] = true;
  33.         echo('<p>Logging you in... If you are not logged in automatically, use the link below:</p>');
  34.         echo('<p><a href="./post.php" title="Log in">Log in manually</a></p>');
  35.         header('Location: ./post.php');
  36.     }
  37.     else
  38.     {
  39.         echo('The password didn\'t match the one in our database, login failed.');
  40.     }
  41. }
  42. else
  43. {  
  44.     if ($_SESSION['loggedin'] == true)
  45.     {
  46.         ?>
  47.         <html>
  48.             <head>
  49.                 <title>KFS - Admin - Newsposting</title>
  50.             </head>
  51.             <body>
  52.                 <h2 style="text-align: center;">KFS - Admin - Newsposting</h2>
  53.                 <p>Post a newsitem using the form below</p>
  54.                 <form method="post" action="./post.php">
  55.                     <label>Your name</label>
  56.                     <br />
  57.                     <input type="text" style="width: 500px;" name="author" />
  58.                     <br />
  59.                     <label>Your message/newsitem</label>
  60.                     <br />
  61.                     <textarea style="width: 500px; height: 450px;" name="content">
  62.                     </textarea>
  63.                     <br />
  64.                     <label>Date of posting (cannot be changed)</label>
  65.                     <br />
  66.                     <?php
  67.                     $datePost = date("d/m-Y H:i");
  68.                     echo("<input type=\"text\" disabled=\"disabled\" value=\"$datePost\" style=\"width: 500px;\" name=\"date\" />");
  69.                     ?>
  70.                     <br />
  71.                     <input type="submit" value="Post!" style="width: 250px;" /><input type="reset" value="Reset Fields" style="width: 250px;" />
  72.                 </form>
  73.                
  74.             </body>
  75.         </html>
  76.         <?php
  77.     }
  78.     else
  79.     {
  80.         echo('You\'re not logged in, please login before using this service.');
  81.     }
  82. }
  83. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement