Jump to content

Recommended Posts

Hey guys,

i need help with my script i don't find how i can let display an login error

please help.

<?php require_once('../Connections/localhost.php');?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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;
}
}
mysql_select_db($database_localhost, $localhost);
	$query_User = "SELECT * FROM users";
	$User = mysql_query($query_User) or die(mysql_error());
	


function GetUser($naam, $password)
{

	global $User;

	while($row = mysql_fetch_array($User))
	{
		if($row["username"] == $naam)
		{
			if($row["password"]  == $password)
			{
				return true;
				}
		}
		
	}
	
	return false;
}
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
}

$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
  $_SESSION['PrevUrl'] = $_GET['accesscheck'];
}

if (isset($_POST['username'])) {
  $loginUsername=$_POST['username'];
  $password=$_POST['password'];
  $MM_fldUserAuthorization = "";
  $MM_redirectLoginSuccess = "../home/";
  $MM_redirectLoginFailed = "index.php";
  $MM_redirecttoReferrer = false;
  mysql_select_db($database_localhost, $localhost);
  
  $LoginRS__query=sprintf("SELECT username, password FROM users WHERE username=%s AND password=%s",
    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 
   
  $LoginRS = mysql_query($LoginRS__query, $localhost) or die(mysql_error());
  $loginFoundUser = mysql_num_rows($LoginRS);
  if ($loginFoundUser) {
     $loginStrGroup = "";
    
	if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;	      

    if (isset($_SESSION['PrevUrl']) && false) {
      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];	
    }
    header("Location: " . $MM_redirectLoginSuccess );
  }
  else {
    header("Location: ". $MM_redirectLoginFailed );
  }
}
?>
<?php
   include '../content/content.php';
   include '../content/menu.php';
?>
			<div class="content">
					<div class="text">
							<div class="contentbox">
 <?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST' ) {

$username = trim(htmlentities(mysql_real_escape_string($_POST['username'])));
$password = trim(htmlentities(mysql_real_escape_string($_POST['password'])));
if (!empty($username) && !empty($password)) {
	if(GetUser($username, $password)){
    	$_SESSION['username'] = $username;
	}
    }  
}
?>
<?php
	if(isset($_SESSION["username"]))
	{
	echo "<center>ur alredy logged in</center><br><br><>";
	}else{
?>
<?php
  if(isset($_SESSION['status']))
  {
    echo $_SESSION['status']; 
    unset($_SESSION['status']);
  } 
?>
<form ACTION="<?php echo $loginFormAction; ?>" METHOD="POST" name="login_form">
<fieldset class="account-info">
<label>Username<br/>
<input type="text" name="username"><br/>
</label>
<label>Password<br/>
<input type="password" name="password"><br/>
</label>
</fieldset>
<fieldset class="account-action">
<input class="btn btn-primary" type="submit" value="Login">
<a class="registerbtn" href="register.php" >Register</a>
</fieldset>
</form>
<?php
}
?>
<?php
	echo "<br/>"."<center>";
   include '../content/copy.php';
   include '../content/bg.php';
	echo "</center>"; 
?>
					</div>
				</div>
			</div>
<video autoplay loop poster="../background/bg.jpg" id="bgvid">
  <source src="../background/bg.webm" type="video/webm">
</video>
<body>
</body>
</html>
<?php
mysql_free_result($User);
?>

Link to comment
https://forums.phpfreaks.com/topic/292506-need-help-with-bad-login-erro-display/
Share on other sites

Ok. Took a further look at the code. 

 

Delete the following blocks of code. They are not needed at all

 

1)

$query_User = "SELECT * FROM users";
	$User = mysql_query($query_User) or die(mysql_error());
	


function GetUser($naam, $password)
{

	global $User;

	while($row = mysql_fetch_array($User))
	{
		if($row["username"] == $naam)
		{
			if($row["password"]  == $password)
			{
				return true;
				}
		}
		
	}
	
	return false;
}

2)

<?php 
if ($_SERVER['REQUEST_METHOD'] == 'POST' ) {

$username = trim(htmlentities(mysql_real_escape_string($_POST['username'])));
$password = trim(htmlentities(mysql_real_escape_string($_POST['password'])));
if (!empty($username) && !empty($password)) {
	if(GetUser($username, $password)){
    	$_SESSION['username'] = $username;
	}
    }  
}
?>

.

 

Next find this line

header("Location: ". $MM_redirectLoginFailed );

And change it to

echo "Invalid/Username or password. Please try again.";

or if you want to display a message and also redirect the user at the same time change it to this instead

header("Refresh: 5; url=$MM_redirectLoginFailed"); // redirect user after 5 seconds
echo "Invalid/Username or password. Please try again."; 
exit;

I have this:

<form ACTION="<?php echo $loginFormAction; ?>" METHOD="POST" name="login_form">
<fieldset class="account-info">
<label>Username<br/>
<input type="text" style="<?php echo $color ['usercolor']?>" name="username"><br/>
</label>
<label>Password<br/>
<input type="password" style="<?php echo $color ['passcolor']?>" name="password"><br/>
</label>
</fieldset>
<fieldset class="account-action">
<input class="btn btn-primary" type="submit" value="Login">
<a class="registerbtn" href="register.php" >Register</a>
</fieldset>
</form>

But i don't know how to send the color

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.