Results 1 to 6 of 6

Thread: Echo Error Message for Incorrect Login

  1. #1

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Echo Error Message for Incorrect Login

    Hi,
    I am having default.php and checklogin.php page.
    When i login from default.php, it checks for correct login from checklogin .php.
    When the login is correct, checklogin.php redirects to other page.
    But if it is wrong, the page redirects to default.php page and here i want to echo as Incorrect Login.
    I am already having Javascript Validation in default.php.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Echo Error Message for Incorrect Login

    you can either:

    • set a query string variable
    • set a cookie
    • or set a session

    that says the login was incorrect. then, check if this query string/cookie/session exists on your main page and display an error message if so.

  3. #3

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Re: Echo Error Message for Incorrect Login

    Ya Thankyou, which is the best one for displaying more errors..

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Echo Error Message for Incorrect Login

    it doesn't matter, that's why I gave you three different options.

  5. #5

    Thread Starter
    Fanatic Member bharanidharanit's Avatar
    Join Date
    Oct 2008
    Location
    India
    Posts
    673

    Re: Echo Error Message for Incorrect Login

    Hi,
    I used the sessions method, but it has some errors. Each and every time when the page loads the "Invalid Login" error message is displayed, even when the page is not posted to check the login.
    checklogin.php coding
    Code:
    if($hash != $userdata['userpwd']) 	
    	{
    		$_SESSION['ErrorLogin'] = "Invalid Login";
    	    header('Location: ../default.php');
    	    //echo "Fails";
    	}
    login.php coding
    Code:
    <?PHP
    session_start();
    if (isset($_SESSION['ErrorLogin']))
    {
    	$error = $_SESSION['ErrorLogin'];											
    echo "$error";
    }

  6. #6
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Echo Error Message for Incorrect Login

    After you print it, you need to clear the session variable, otherwise it will stay set for as long as the session exists.

    Code:
    <?php
    session_start();
    if (isset($_SESSION['ErrorLogin']))
    {
    	$error = $_SESSION['ErrorLogin'];											
    	echo "$error";
    	unset($_SESSION['ErrorLogin']);
    }


    Has someone helped you? Then you can Rate their helpful post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width