Advertisement
Guest User

Untitled

a guest
Apr 12th, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. <?php
  2. # FileName="Connection_php_mysql.htm"
  3. # Type="MYSQL"
  4. # HTTP="true"
  5. $hostname_myCon = "localhost";
  6. $database_myCon = "thesis";
  7. $username_myCon = "root";
  8. $password_myCon = "";
  9. $myCon = mysql_connect($hostname_myCon, $username_myCon, $password_myCon) or trigger_error(mysql_error(),E_USER_ERROR);
  10. ?>
  11. <?php
  12. if (!function_exists("GetSQLValueString")) {
  13. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  14. {
  15. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  16.  
  17. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  18.  
  19. switch ($theType) {
  20. case "text":
  21. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  22. break;
  23. case "long":
  24. case "int":
  25. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  26. break;
  27. case "double":
  28. $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
  29. break;
  30. case "date":
  31. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  32. break;
  33. case "defined":
  34. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  35. break;
  36. }
  37. return $theValue;
  38. }
  39. }
  40. ?>
  41. <?php
  42. // *** Validate request to login to this site.
  43. if (!isset($_SESSION)) {
  44. session_start();
  45. }
  46.  
  47. if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  48. //to fully log out a visitor we need to clear the session varialbles
  49. $_SESSION['loggedin'] = NULL;
  50. $_SESSION['username'] = NULL;
  51. $_SESSION['MM_UserGroup'] = NULL;
  52. $_SESSION['PrevUrl'] = NULL;
  53. unset($_SESSION['username']);
  54. unset($_SESSION['MM_UserGroup']);
  55. unset($_SESSION['PrevUrl']);
  56.  
  57. $logoutGoTo = "";
  58. if ($logoutGoTo) {
  59. header("Location: $logoutGoTo");
  60. exit;
  61. }
  62. }
  63.  
  64. $loginFormAction = $_SERVER['PHP_SELF'];
  65. if (isset($_GET['accesscheck'])) {
  66. $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  67. }
  68.  
  69. if (isset($_POST['login'])) {
  70. $username= mysql_real_escape_string($_POST['username']);
  71. $password= mysql_real_escape_string($_POST['password']);
  72. $MM_fldUserAuthorization = "";
  73. $MM_redirectLoginSuccess = "home.php";
  74.  
  75. $MM_redirecttoReferrer = false;
  76. mysql_select_db($database_myCon, $myCon);
  77.  
  78. $LoginRS__query=sprintf("SELECT username, password FROM registration WHERE username=%s AND password=%s",
  79. GetSQLValueString($username, "text"), GetSQLValueString($password, "text"));
  80.  
  81. $LoginRS = mysql_query($LoginRS__query, $myCon) or die(mysql_error());
  82. $loginFoundUser = mysql_num_rows($LoginRS);
  83. if ($loginFoundUser) {
  84. $loginStrGroup = "";
  85.  
  86. //declare two session variables and assign them
  87.  
  88. $_SESSION['username'] = $username;
  89. $_SESSION['password'] = $password;
  90.  
  91. if (isset($_SESSION['PrevUrl']) && false) {
  92. $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
  93. }
  94. echo "<script>function redirect() { document.login.access.click() } setTimeout('redirect()',3000);</script>
  95. <p>Logged in successfully ". $_SESSION['username'] .". Redirecting ...</p>
  96.  
  97. <div style='display:none'>
  98. <form name='login' method='post' action='home.php'>
  99.  
  100. <label for='email'>Username</label>
  101. <input type='text' name='username' id='textfield' value=".$_SESSION['username'].">
  102. <label for='pass'>Password</label>
  103. <input type='password' name='password' id='textfield2' value=".$_SESSION['password']." >";
  104. echo "<input type='submit' name='access' id='button' value='Login'></div>";
  105. if (!session_id())
  106. session_start();
  107. $_SESSION['username'] = true;
  108. die();
  109. // header('Location: home.php');
  110.  
  111. //header("Location: " . $MM_redirectLoginSuccess );
  112. }
  113. else {
  114. echo "
  115. <meta http-equiv='refresh' content='2;url=javascript:window.history.back()'>
  116. <p>It appears that you have entered an incorrect password</p>";
  117. }
  118. }
  119.  
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement