login failed message

  • dheerhot
  • Novice
  • Novice
  • User avatar
  • Joined: Jan 11, 2009
  • Posts: 34
  • Status: Offline

Post February 27th, 2009, 7:49 am

hello guys, here i have a login form & i want to throw a message as the login failed, please any one help me to do this, below is the login code (made by using dreamweaver)

Code: [ Select ]
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}

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

if (isset($_POST['text'])) {
$loginUsername=$_POST['text'];
$password=$_POST['text2'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "profile.php";
$MM_redirectLoginFailed = "login.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_apnahome, $apnahome);

$LoginRS__query=sprintf("SELECT username, password FROM register WHERE username='%s' AND password='%s'",
    get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));

$LoginRS = mysql_query($LoginRS__query, $apnahome) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
    $loginStrGroup = "";
    
    //declare two session variables and assign them
    $_SESSION['MM_Username'] = $loginUsername;
    $_SESSION['MM_UserGroup'] = $loginStrGroup;    

    if (isset($_SESSION['PrevUrl']) && true) {
     $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
    }
    header("Location: " . $MM_redirectLoginSuccess );
}
else {
    header("Location: ". $MM_redirectLoginFailed ); 
}
}
?>
  1. <?php
  2. // *** Validate request to login to this site.
  3. if (!isset($_SESSION)) {
  4. session_start();
  5. }
  6. $loginFormAction = $_SERVER['PHP_SELF'];
  7. if (isset($_GET['accesscheck'])) {
  8. $_SESSION['PrevUrl'] = $_GET['accesscheck'];
  9. }
  10. if (isset($_POST['text'])) {
  11. $loginUsername=$_POST['text'];
  12. $password=$_POST['text2'];
  13. $MM_fldUserAuthorization = "";
  14. $MM_redirectLoginSuccess = "profile.php";
  15. $MM_redirectLoginFailed = "login.php";
  16. $MM_redirecttoReferrer = true;
  17. mysql_select_db($database_apnahome, $apnahome);
  18. $LoginRS__query=sprintf("SELECT username, password FROM register WHERE username='%s' AND password='%s'",
  19.     get_magic_quotes_gpc() ? $loginUsername : addslashes($loginUsername), get_magic_quotes_gpc() ? $password : addslashes($password));
  20. $LoginRS = mysql_query($LoginRS__query, $apnahome) or die(mysql_error());
  21. $loginFoundUser = mysql_num_rows($LoginRS);
  22. if ($loginFoundUser) {
  23.     $loginStrGroup = "";
  24.     
  25.     //declare two session variables and assign them
  26.     $_SESSION['MM_Username'] = $loginUsername;
  27.     $_SESSION['MM_UserGroup'] = $loginStrGroup;    
  28.     if (isset($_SESSION['PrevUrl']) && true) {
  29.      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
  30.     }
  31.     header("Location: " . $MM_redirectLoginSuccess );
  32. }
  33. else {
  34.     header("Location: ". $MM_redirectLoginFailed ); 
  35. }
  36. }
  37. ?>
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post February 27th, 2009, 7:49 am

  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Joined: Jan 14, 2009
  • Posts: 162
  • Loc: India-Kolkata
  • Status: Offline

Post February 27th, 2009, 10:27 am

in the above code/page i don't think you can throw any log in failed msg since you are redirecting using php header. What you can do is, add some query strings to login.php

like change this
Code: [ Select ]
 
  $MM_redirectLoginFailed = "login.php";
 
  1.  
  2.   $MM_redirectLoginFailed = "login.php";
  3.  


to

Code: [ Select ]
 
  $MM_redirectLoginFailed = "login.php?action=lfail";
 
  1.  
  2.   $MM_redirectLoginFailed = "login.php?action=lfail";
  3.  


and in login.php
create if loop shown below
Code: [ Select ]
 
$action = $_GET["lfail"];
if($action=="lfail")
{
      echo "Log in Failed. etc...";
}
 
  1.  
  2. $action = $_GET["lfail"];
  3. if($action=="lfail")
  4. {
  5.       echo "Log in Failed. etc...";
  6. }
  7.  


**********************************************
Another way is to use session variable
in the else part where you're redirecting to login
set this
Code: [ Select ]
 
   else {
      $_SESSION["faction"] = "lfail";  
     header("Location: ". $MM_redirectLoginFailed );    
   }
 
  1.  
  2.    else {
  3.       $_SESSION["faction"] = "lfail";  
  4.      header("Location: ". $MM_redirectLoginFailed );    
  5.    }
  6.  


and change the request parameter from
Code: [ Select ]
 
$action = $_GET["lfail"];
 
  1.  
  2. $action = $_GET["lfail"];
  3.  

to
Code: [ Select ]
 
$action = $_SESSION["faction"];
 
  1.  
  2. $action = $_SESSION["faction"];
  3.  


I hope those above works....
Wrap Up your Big Url | Mariana World Community
  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8212
  • Loc: USA
  • Status: Offline

Post February 27th, 2009, 2:46 pm

dude, instead of
PHP Code: [ Select ]
header("Location: ". $MM_redirectLoginFailed );
Echo the message.But if you want to do it dark_lord's way, you can do it:
PHP Code: [ Select ]
if($_GET["lfail"] == 'lfail')
{
    echo "Log in Failed. etc...";
}
  1. if($_GET["lfail"] == 'lfail')
  2. {
  3.     echo "Log in Failed. etc...";
  4. }
"Bring forth therefore fruits meet for repentance:" Matthew 3:8

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 105 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.