daily pastebin goal
16%
SHARE
TWEET

Untitled

a guest Sep 3rd, 2018 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     //Common files and functions
  3.     session_start();
  4.     require_once('dbconnect.php');
  5.    
  6.     //Check for valid session information on pages
  7.     function validate_session(){
  8.         $ip       = $_SERVER['REMOTE_ADDR'];
  9.         $username = $_SESSION['username'];
  10.         $userid   = $_SESSION['uid'];
  11.        
  12.         $sql = mysql_query("SELECT * FROM `member` where (id='$userid' AND ip='$ip' AND username='$username')");
  13.        
  14.         if(mysql_num_rows($sql) == 1){
  15.             return true;
  16.         } else {
  17.             header("Location: ../../../index.php?notloggedin=1");
  18.             exit();
  19.         }
  20.     }
  21.    
  22.     //Set session defaults if not set yet
  23.     function session_defaults(){
  24.         $_SESSION['uid']      = 0;
  25.         $_SESSION['username'] = '';
  26.         $_SESSION['ip']       = '';
  27.     }
  28.    
  29.     //Hash password parameter
  30.     function hashPassword($password){
  31.         $password = stripslashes(mysql_real_escape_string($password));
  32.         $newPassword = md5($password);
  33.         return $newPassword;
  34.     }
  35.    
  36.     //Set sessions with given parameters
  37.     function set_session($id, $username){
  38.         $_SESSION['uid']      = $id;
  39.         $_SESSION['username'] = $username;
  40.     }
  41.    
  42.     //Generate random password
  43.     function random_pass(){
  44.         $chars = "abcdefghijkmnopqrstuvwxyz023456789";
  45.         srand((double)microtime()*1000000);
  46.         $i = 0;
  47.         $pass = '' ;
  48.         while ($i <= 7) {
  49.             $num = rand() % 33;
  50.             $tmp = substr($chars, $num, 1);
  51.             $pass = $pass . $tmp;
  52.             $i++;
  53.         }
  54.         return $pass;  
  55.     }
  56.    
  57.     //Destroy session
  58.     function logout() {
  59.         session_destroy();
  60.     }
  61. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top