Guest User

Untitled

a guest
Apr 21st, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. <!-- user.php -->
  2. <?php
  3. session_start();
  4. ob_start();
  5. $user = 'admin';
  6. $pass = 'admin';
  7.  
  8. $action = $_GET['action'];
  9. switch($action) {
  10. // Login.
  11. case 'login':
  12. $what = $_GET['what'];
  13. switch($what) {
  14. case 'process':
  15. $username = $_POST['username'];
  16. $password = $_POST['password'];
  17.  
  18. $username = strip_tags($username);
  19. $password = strip_tags($password);
  20. $username = htmlspecialchars($username);
  21. $password = htmlspecialchars($password);
  22.  
  23. if($username == $user && $password == $pass) {
  24. $agent = $_SERVER['HTTP_USER_AGENT'];
  25. $ip = $_SERVER['REMOTE_ADDR'];
  26.  
  27. $_SESSION['login'] = 'admin';
  28. $_SESSION['agent'] = $agent;
  29. $_SESSION['ip'] = $ip;
  30.  
  31. header('Location: index.php?action=admin');
  32. } else {
  33. echo '<p style="font-size: 12px;">Contraseña/Usuario incorrecto. Volver <a style="text-decoration: none;" href="index.php">atrás</a>';
  34. }
  35. break;
  36.  
  37. // Login form.
  38. default:
  39. include('login_form.php');
  40. }
  41. break;
  42.  
  43. // Logout.
  44. case 'logout':
  45. session_destroy();
  46. header('Location: index.php');
  47. break;
  48.  
  49. // Admin page.
  50. case 'admin':
  51. if(isset($_SESSION['login'])) {
  52. $agent = $_SERVER['HTTP_USER_AGENT'];
  53. $ip = $_SERVER['REMOTE_ADDR'];
  54.  
  55. if($agent == $_SESSION['agent'] && $ip == $_SESSION['ip']) {
  56. include('admin_page.php');
  57. } else {
  58. header('location: ?action=login');
  59. }
  60. } else {
  61. header('location: ?action=login');
  62. }
  63. break;
  64.  
  65. default:
  66. include('login_form.php');
  67. }
  68.  
  69. $page_content = ob_get_clean();
  70. include('layout.php');
  71. ?>
  72.  
  73. <!-- admin_page.php -->
  74. <div class="login">
  75. <table border="0" width="100%" height="20px">
  76. <tr>
  77. <td align="right" valign="middle" style="padding-right: 8px;"><font style="font-size: 12px;">Conectado como: <?php echo $user; ?> | <a style="text-decoration: none;" href="index.php?action=logout">Salir</a></font>
  78. </td>
  79. </tr>
  80. </table>
  81. </div>
  82.  
  83. <!-- login_form.php -->
  84. <div class="login">
  85. <table border="0" width="100%" height="20px">
  86. <tr>
  87. <td align="right" valign="middle" style="padding-right: 8px;">
  88. <form action="index.php?action=login&what=process" method="POST">
  89. <font style="font-size: 12px;">Usuario: </font>
  90. <input tabindex="1" type="text" name="username" size="15" style="width: 80px;" class="loginfield" />
  91. <font style="font-size: 12px;">Contrase&ntilde;a:</font>
  92. <input tabindex="1" type="password" name="password" size="15" style="width: 80px;" class="loginfield" />
  93. <input type="submit" value="Entrar" name="submit" class="loginbutton" />
  94. </form>
  95. </td>
  96. </tr>
  97. </table>
  98. </div>
  99.  
  100. <!-- layout.php -->
  101. <div id="header">
  102. <div>
  103. <a href="index.php"><img src="img/banner.gif" height="110" border="0" /></a>
  104. </div>
  105. </div>
  106. <?php echo $page_content; ?>
Add Comment
Please, Sign In to add comment