Advertisement
Guest User

Untitled

a guest
May 31st, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. require_once 'connect.inc.php';
  2. require_once 'core.inc.php';
  3.  
  4. if(isset($_POST['username']) && isset($_POST['password'])){
  5. $username=$_POST['username'];
  6. $password=$_POST['password'];
  7. $password_hash=md5($password);
  8. if(!empty($username) && !empty($password)){
  9. $query="SELECT `id` FROM `login` WHERE `username`='$username' AND `password`='$password_hash'";
  10. if($query_run = mysqli_query($stat,$query)){
  11. $query_num_rows = mysqli_num_rows($query_run);
  12. if($query_num_rows == 0){
  13. echo 'You have entered wrong username or password !';
  14. }
  15. else if($query_num_rows == 1){
  16. function mysqli_result($res, $row, $field) {
  17. $res->data_seek($row);
  18. $datarow = $res->fetch_array();
  19. return $datarow[$field];
  20. }
  21. $user_id= mysqli_result($query_run, 0,'id');
  22. $_SESSION['user_id'] = $user_id;
  23. header('Location: index.php');
  24. }
  25. }
  26. else
  27. {
  28. echo 'You have entered wrong username or password !';
  29. }
  30. }else {
  31. echo 'You must have to enter username and password';
  32. }
  33. }
  34. <form action="<?php echo $server; ?>" method="POST">
  35. Username:
  36. <input type="text" placeholder="Enter the userid" name="username">
  37. Password:
  38. <input type="password" placeholder="Enter your password" name="password">
  39. <input type="submit" value="Log in">
  40.  
  41. require_once 'core.inc.php';
  42. require_once 'connect.inc.php';
  43.  
  44. if(get_status()){
  45. $firstname=getinfo('firstname');
  46. $lastname=getinfo('lastname');
  47. echo 'You are logged in ,'.$firstname.' '.$lastname.'';
  48. echo "<br><a href='logout.php'>Logout</a><br>";
  49. }
  50. else {
  51. include_once 'login.php';
  52. }
  53.  
  54. session_start();
  55. ob_start();
  56. $server =$_SERVER['SCRIPT_NAME'];
  57. @$ref_url=$_SERVER['HTTP_REFERER'];
  58. function get_status(){
  59. if(isset($_SESSION['user_id']) && !empty($_SESSION['user_id'])){
  60. return true;
  61. }
  62. else
  63. return false;
  64. }
  65.  
  66. function getinfo($field){
  67. $get_query="SELECT `$field` FROM `login` WHERE `id`='".$_SESSION['user_id']."'";
  68. require 'connect.inc.php';
  69. if($query_run=mysqli_query($stat,$get_query)){
  70. function mysqli_result($res, $row, $f) {
  71. $res->data_seek($row);
  72. $datarow = $res->fetch_array();
  73. return $datarow[$f];
  74. }
  75. if($query_result=mysqli_result($query_run,0,$field)){
  76. return $query_result;
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement