Guest User

Untitled

a guest
Jul 23rd, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. <?php
  2. error_reporting(0);
  3. include('config.php');
  4. $page = mysql_real_escape_string($_GET['page']);
  5. session_start();
  6. if($_SERVER["REQUEST_METHOD"] == "POST") {
  7.    $flag = false;
  8.    $errmsg = $msg;
  9.    $user = $_POST['username'];
  10.    $pass = $_POST['password'];
  11.    if(!$user) {
  12.       $msg = "NoUsername";
  13.       $flag = true;
  14.    }
  15.    else if(!$pass) {
  16.       $msg = "NoPassword";
  17.       $flag = true;
  18.    }
  19.    if($flag == true) {
  20.       header("Location: index.php?error=".$msg."");
  21.    } else {
  22.       $query = "SELECT * FROM users WHERE username='$user' AND password='$pass'";
  23.       $result = mysql_query($query);
  24.       $check = mysql_num_rows($result);
  25.  
  26.       if($check == 1) {
  27.          $_SESSION['user'] = $user;
  28.          $_SESSION['logged'] = true;
  29.          header("location: index.php");
  30.       } else {
  31.          $msg = "UserNotFound";
  32.          header("location: index.php?error=".$msg."");
  33.       }
  34.    }
  35. }
  36. if(!$_SESSION['user']) {
  37. echo "
  38. <html>
  39. <link rel='stylesheet' href='css/style.css' type='text/css' media='screen' title='default' />
  40. <body id='body-message'>
  41.   <p id='message'>
  42.    <center>
  43.   <form action='index.php' method='post' name='login' id='login'>
  44.   <input type='text' name='username' id='username' value='Username'>
  45.   <br>
  46.   <input type='Password' name='password' id='Password' value='Password'>
  47.   <br>
  48.   <input type='submit' id='login' value='login'>
  49.   </form>
  50.   </center>
  51.   </p>
  52. </body>
  53. </html>";
  54. }
  55. if($_SESSION['logged'] = true) {
  56.     switch($page) {
  57.         default:
  58.             include('templates/404.template.php');
  59.             break;
  60.         case !$page:
  61.             include('templats./body.template.php');
  62.             break;
  63.         case 'news':
  64.             include('templates/body.template.php');
  65.             break;
  66.     }
  67. }
  68. ?>
  69. <body>
  70. </body>
  71. </html>
Add Comment
Please, Sign In to add comment