Advertisement
tjromano

Functions

Aug 21st, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.10 KB | None | 0 0
  1. <?php
  2.  
  3. //function to get the date
  4. function last_login()
  5. {
  6.     $date = gmdate("Y-m-d");
  7.     return $date;
  8. }
  9.  
  10. //function that sets the session variable
  11. function sess_vars($base_dir, $server, $dbusername, $dbpassword, $db_name, $table_name, $user, $pass)
  12. {
  13.  
  14.  
  15.     //make connection to dbase
  16.     $connection = @mysql_connect($server, $dbusername, $dbpassword)
  17.                 or die(mysql_error());
  18.                
  19.     $db = @mysql_select_db($db_name,$connection)
  20.                 or die(mysql_error());
  21.                
  22.     $sql = "SELECT * FROM $table_name WHERE username = '$user' and password = password('$pass')";
  23.  
  24.     $result = @mysql_query($sql, $connection) or die(mysql_error());
  25.  
  26.  
  27.     //get the number of rows in the result set
  28.     $num = mysql_num_rows($result);
  29.  
  30.     //set session variables if there is a match
  31.     if ($num != 0)
  32.     {
  33.         while ($sql = mysql_fetch_object($result))
  34.         {
  35.             $_SESSION[first_name]   = $sql -> firstname;
  36.             $_SESSION[last_name]    = $sql -> lastname;
  37.             $_SESSION[user_name]    = $sql -> username;      
  38.             $_SESSION[password]     = $sql -> password;
  39.             $_SESSION[group1]       = $sql -> group1;
  40.             $_SESSION[group2]       = $sql -> group2;
  41.             $_SESSION[group3]       = $sql -> group3;
  42.             $_SESSION[pchange]      = $sql -> pchange;  
  43.             $_SESSION[email]        = $sql -> email;
  44.             $_SESSION[redirect]     = $sql -> redirect;
  45.             $_SESSION[verified]     = $sql -> verified;
  46.             $_SESSION[last_login]   = $sql -> last_login;
  47.         }
  48.     }else{
  49.         $_SESSION[redirect] = "$base_dir/errorlogin.html";
  50.     }
  51. }
  52.  
  53. //functions that will determine if access is allowed
  54. function allow_access($group)
  55. {
  56.     if ($_SESSION[group1] == "$group" || $_SESSION[group2] == "$group" || $_SESSION[group3] == "$group" ||
  57.         $_SESSION[group1] == "Administrators" || $_SESSION[group2] == "Administrators" || $_SESSION[group3] == "Administrators" ||
  58.         $_SESSION[user_name] == "$group")
  59.         {
  60.             $allowed = "yes";
  61.         }else{
  62.             $allowed = "no";
  63.         }
  64.     return $allowed;
  65. }
  66.  
  67. //function to check the length of the requested password
  68. function password_check($min_pass, $max_pass, $pass)
  69. {
  70.  
  71.     $valid = "yes";
  72.     if ($min_pass > strlen($pass) || $max_pass < strlen($pass))
  73.     {
  74.         $valid = "no";
  75.     }
  76.  
  77.     return $valid;
  78. }
  79.  
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement