Advertisement
Guest User

Untitled

a guest
May 10th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. ////index.php/////
  2. /////////////////
  3. <?php
  4. require_once('config.php');
  5. require_once('inc/style.css');
  6. include('inc/functions.php');
  7.  
  8. if(is_logged_in()) /** Use function is_logged_in  */
  9. {  
  10. echo 'hello';  
  11. } else { /** If is_logged_in is not set: ELSE  */
  12.     require('inc/login.php');
  13. }
  14. ?>
  15.  
  16. ////functions.php/////
  17. /////////////////////
  18. function is_logged_in() /** Checks if user is logged in */
  19. {
  20.     $islogged = false; /** Set variable FALSE  */
  21.    
  22.     if (isset($_SESSION['username'], $_SESSION['password'])) { /** If username/password isset */
  23.         $islogged = true; /** If username/password isset: variable TRUE" */  
  24.     }
  25.    
  26.     return $islogged; /** Return TRUE or FALSE */
  27. }
  28.  
  29. ////login.php/////
  30. /////////////////
  31. <?php
  32.  if($_GET['do'] == register){
  33.     include('inc/register.php');
  34. }else{
  35.  
  36.  ?>
  37. <div id="login">
  38. <form name="login" method="post" action="">
  39. Username:
  40. <br/>
  41. <input type="text" name="username" id="username" class="textfield">
  42. <br/>
  43. Password:
  44. <br/>
  45. <input type="password" name="password" id="password" class="textfield1">
  46. <br/>
  47. <input type="submit" name="login" value="Login" class="submit">
  48. </form>
  49. <a href='?do=register'>Register now!</a><br/>
  50. <?php
  51.     if (isset($_POST['login'])) {
  52.         $username = $_POST['username'];
  53.         $password = (md5($_POST['password']));
  54.  
  55.         $query = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
  56.         $result = mysql_query($query);
  57.         if (mysql_num_rows($result) > 0) {
  58.             $_SESSION['username'] = $_POST['username'];
  59.             $_SESSION['password'] = $_POST['password'];
  60.             redirect('index.php', '0');
  61.         } else {
  62.             echo 'Wrong information.';
  63.         }
  64.  
  65.     }
  66. }
  67. ?>
  68. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement