Advertisement
Guest User

Untitled

a guest
May 12th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.01 KB | None | 0 0
  1. <?php require_once('Connections/CAIP.php'); ?>
  2.  
  3.  
  4. <?php
  5. if (!function_exists("GetSQLValueString")) {
  6. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  7. {
  8.   if (PHP_VERSION < 6) {
  9.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  10.   }
  11.  
  12.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  13.  
  14.   switch ($theType) {
  15.     case "text":
  16.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  17.       break;    
  18.     case "long":
  19.     case "int":
  20.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  21.       break;
  22.     case "double":
  23.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  24.       break;
  25.     case "date":
  26.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  27.       break;
  28.     case "defined":
  29.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  30.       break;
  31.   }
  32.   return $theValue;
  33. }
  34. }
  35.  
  36. mysql_select_db($database_CAIP, $CAIP);
  37. $query_login = "SELECT * FROM utilizadores";
  38. $login = mysql_query($query_login, $CAIP) or die(mysql_error());
  39. $row_login = mysql_fetch_assoc($login);
  40. $totalRows_login = mysql_num_rows($login);
  41.  
  42. mysql_select_db($database_CAIP, $CAIP);
  43. $query_Recordset1 = "SELECT * FROM textos";
  44. $Recordset1 = mysql_query($query_Recordset1, $CAIP) or die(mysql_error());
  45. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  46. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  47. ?>
  48.  
  49. <?php
  50. // *** Validate request to login to this site.
  51. if (!isset($_SESSION)) {
  52.   session_start();
  53. }
  54.  
  55. $loginFormAction = $_SERVER['PHP_SELF'];
  56. if (isset($_GET['accesscheck'])) {
  57.   $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  58. }
  59.  
  60. if (isset($_POST['user'])) {
  61.   $loginUsername=$_POST['user'];
  62.   $password=$_POST['password'];
  63.   $MM_fldUserAuthorization = "nivel";
  64.   $MM_redirectLoginSuccess = "company.php";
  65.   $MM_redirectLoginFailed = "company.php";
  66.   $MM_redirecttoReferrer = true;
  67.   mysql_select_db($database_CAIP, $CAIP);
  68.    
  69.   $LoginRS__query=sprintf("SELECT * FROM utilizadores WHERE utilizador=%s AND password=%s AND id_utilizador=1 ",
  70.   GetSQLValueString($loginUsername, "text"), GetSQLValueString($id_utilizador, "int"), GetSQLValueString($password, "text"));
  71.    
  72.   $LoginRS = mysql_query($LoginRS__query, $CAIP) or die(mysql_error());
  73.   $loginFoundUser = mysql_num_rows($LoginRS);
  74.  
  75.  
  76.   if ($loginFoundUser) {
  77.     echo mysql_error();
  78.     $loginStrGroup  = mysql_result($LoginRS,0,'nivel');
  79.     $userid = mysql_result($LoginRS,0,'id_user');
  80.    
  81.     //declare two session variables and assign them
  82.     $_SESSION['MM_Username'] = $loginUsername;
  83.     $_SESSION['MM_UserGroup'] = $loginStrGroup;    
  84.     $_SESSION['MM_ID'] = $userid;
  85.  
  86.  
  87.     if (isset($_SESSION['PrevUrl']) && true) {
  88.       $MM_redirectLoginSuccess = $_SESSION['PrevUrl']; 
  89.     }
  90.     header("Location: " . $MM_redirectLoginSuccess );
  91.   }
  92.   else {
  93.     header("Location: ". $MM_redirectLoginFailed );
  94.   }
  95. }
  96. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement