Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- # FileName="Connection_php_mysql.htm"
- # Type="MYSQL"
- # HTTP="true"
- $hostname_myCon = "localhost";
- $database_myCon = "thesis";
- $username_myCon = "root";
- $password_myCon = "";
- $myCon = mysql_connect($hostname_myCon, $username_myCon, $password_myCon) or trigger_error(mysql_error(),E_USER_ERROR);
- ?>
- <?php
- if (!function_exists("GetSQLValueString")) {
- function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
- {
- $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
- $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
- switch ($theType) {
- case "text":
- $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
- break;
- case "long":
- case "int":
- $theValue = ($theValue != "") ? intval($theValue) : "NULL";
- break;
- case "double":
- $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
- break;
- case "date":
- $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
- break;
- case "defined":
- $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
- break;
- }
- return $theValue;
- }
- }
- ?>
- <?php
- // *** Validate request to login to this site.
- if (!isset($_SESSION)) {
- session_start();
- }
- if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
- //to fully log out a visitor we need to clear the session varialbles
- $_SESSION['loggedin'] = NULL;
- $_SESSION['username'] = NULL;
- $_SESSION['MM_UserGroup'] = NULL;
- $_SESSION['PrevUrl'] = NULL;
- unset($_SESSION['username']);
- unset($_SESSION['MM_UserGroup']);
- unset($_SESSION['PrevUrl']);
- $logoutGoTo = "";
- if ($logoutGoTo) {
- header("Location: $logoutGoTo");
- exit;
- }
- }
- $loginFormAction = $_SERVER['PHP_SELF'];
- if (isset($_GET['accesscheck'])) {
- $_SESSION['PrevUrl'] = $_GET['accesscheck'];
- }
- if (isset($_POST['login'])) {
- $username= mysql_real_escape_string($_POST['username']);
- $password= mysql_real_escape_string($_POST['password']);
- $MM_fldUserAuthorization = "";
- $MM_redirectLoginSuccess = "home.php";
- $MM_redirecttoReferrer = false;
- mysql_select_db($database_myCon, $myCon);
- $LoginRS__query=sprintf("SELECT username, password FROM registration WHERE username=%s AND password=%s",
- GetSQLValueString($username, "text"), GetSQLValueString($password, "text"));
- $LoginRS = mysql_query($LoginRS__query, $myCon) or die(mysql_error());
- $loginFoundUser = mysql_num_rows($LoginRS);
- if ($loginFoundUser) {
- $loginStrGroup = "";
- //declare two session variables and assign them
- $_SESSION['username'] = $username;
- $_SESSION['password'] = $password;
- if (isset($_SESSION['PrevUrl']) && false) {
- $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
- }
- echo "<script>function redirect() { document.login.access.click() } setTimeout('redirect()',3000);</script>
- <p>Logged in successfully ". $_SESSION['username'] .". Redirecting ...</p>
- <div style='display:none'>
- <form name='login' method='post' action='home.php'>
- <label for='email'>Username</label>
- <input type='text' name='username' id='textfield' value=".$_SESSION['username'].">
- <label for='pass'>Password</label>
- <input type='password' name='password' id='textfield2' value=".$_SESSION['password']." >";
- echo "<input type='submit' name='access' id='button' value='Login'></div>";
- if (!session_id())
- session_start();
- $_SESSION['username'] = true;
- die();
- // header('Location: home.php');
- //header("Location: " . $MM_redirectLoginSuccess );
- }
- else {
- echo "
- <meta http-equiv='refresh' content='2;url=javascript:window.history.back()'>
- <p>It appears that you have entered an incorrect password</p>";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement