Advertisement
Guest User

Untitled

a guest
Mar 31st, 2011
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.37 KB | None | 0 0
  1. the login script:
  2.  
  3. <?php
  4. $host="localhost"; // Host name
  5. $username=""; // Mysql username
  6. $password=""; // Mysql password
  7. $db_name=""; // Database name
  8. $tbl_name="members"; // Table name
  9.  
  10. // Connect to server and select databse.
  11. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  12. mysql_select_db("$db_name")or die("cannot select DB");
  13.  
  14. // username and password sent from form
  15. $myusername=$_POST['myusername'];
  16. $mypassword=$_POST['mypassword'];
  17.  
  18. // To protect MySQL injection (more detail about MySQL injection)
  19. $myusername = stripslashes($myusername);
  20. $mypassword = stripslashes($mypassword);
  21. $myusername = mysql_real_escape_string($myusername);
  22. $mypassword = mysql_real_escape_string($mypassword);
  23.  
  24. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  25. $result=mysql_query($sql);
  26.  
  27. // Mysql_num_row is counting table row
  28. $count=mysql_num_rows($result);
  29. // If result matched $myusername and $mypassword, table row must be 1 row
  30.  
  31.  
  32. if($count){
  33.             session_start();
  34.            session_regenerate_id();
  35.             $_SESSION['SESS_USERNAME'] = $myusername;
  36.             $_SESSION['SESS_PASSWORD'] = $mypassword;
  37.             session_write_close();
  38.            header("location: login_success.php");
  39. }
  40.      
  41.        else
  42.         {
  43.          echo"<html>
  44.        <head>
  45.        <link href='styles.css' rel='stylesheet' type='text/css'/>
  46.        </head>
  47.        <body>
  48.        <div id='main'>
  49.        <div id='header'>
  50.        </div>
  51.        <div id='contentWrapper'>
  52.        <div id='leftBox'>
  53.        <div id='leftBoxContent'>
  54.        <div id='lightBox'>
  55.         </div>
  56.        </div>
  57.       </div>
  58.       <div id='rightBox'>
  59.     </div>
  60.       <div id='content'>
  61.        <p>Wrong Username or Bad Password.</p>
  62.        <p><a href='./index.php'>Click Here</a> to try again.</p>
  63.    </div>
  64.    <br class='clearFloat'/>
  65.  </div>
  66.  <div id='footer'></div>
  67. </div>
  68.        </body>
  69.        </html>";
  70.         }
  71. ?>
  72.  
  73. check login script:
  74.  
  75. <?php
  76. session_start();
  77. if(!isset($_SESSION['SESS_USERNAME']) || !isset($_SESSION['SESS_PASSWORD']) || (trim($_SESSION['SESS_USERNAME']) == '')) {
  78.                 //someone's not logged in
  79.         header("location: index.php"); //it's suppose to actually be there
  80.                 exit();
  81. }
  82. ?>
  83.  
  84. and whats on top of every page:
  85.  
  86. <?php
  87. require_once("checklogin.php");
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement