1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Ajax Login Script

Discussion in 'Programming & Webmastering' started by kurosagi01, Apr 16, 2014.

  1. kurosagi01

    kurosagi01

    Joined:
    Mar 21, 2009
    Messages:
    4,264 (1.89/day)
    Thanks Received:
    464
    Location:
    Northampton,UK
    Hey guys i need some help with this login page of mine which implements the use of Ajax.
    I have followed this tutorial:
    http://www.91weblessons.com/php-ajax-login-validation-tutorial/
    Now assuming if i have declared my variables correctly because when i enter the login details it echos "correct" but if i didn't it echo "enter correct details" or leave the text blank it ask me to fill the spaces.
    The issue is its not parsing through to the index.php script correctly,i have to refresh the page for it to take me to the index page.
    Any help or advice be great here's what my codes look like:
    login.php:
    processed.php:
    index.php:
    logout.php:
     
  2. arskatb

    arskatb

    Joined:
    Feb 21, 2014
    Messages:
    206 (0.45/day)
    Thanks Received:
    45
    Location:
    Finland
    No encryption of the received password?
     
  3. kurosagi01

    kurosagi01

    Joined:
    Mar 21, 2009
    Messages:
    4,264 (1.89/day)
    Thanks Received:
    464
    Location:
    Northampton,UK
    The only encryption i got is it display the stars instead of actual text when entered.
     
  4. ste2425

    ste2425

    Joined:
    May 27, 2008
    Messages:
    3,503 (1.37/day)
    Thanks Received:
    417
    Location:
    Huddersfield, uk
    Code:
    $("#flash").hide();
    if(result=='correct'){
    window.location='list.php';
    }
    What is list.php?

    In your login page your redirecting to list.php after a successful ajax call. Maybe that's causing problems?
     
  5. kurosagi01

    kurosagi01

    Joined:
    Mar 21, 2009
    Messages:
    4,264 (1.89/day)
    Thanks Received:
    464
    Location:
    Northampton,UK
    To be honest the index.php was a test page,i have managed to get to direct it to the list.php which is my intended page. However instead of automatically directing me to the list page it only echos "correct" and i have to refresh my browser to display the list page.
     
  6. ste2425

    ste2425

    Joined:
    May 27, 2008
    Messages:
    3,503 (1.37/day)
    Thanks Received:
    417
    Location:
    Huddersfield, uk
    Excuse me but i have never used PHP before however, when making an AJAX call with AngularJS and NodeJS server side you cannot perform redirects server side due to it being an ajax call. Im assuming that your redirect is client side. I know window.location is a JavaScript thing but didn't know it there was something similar to PHP

    If you stick a break point on the window.location. Is it being hit? is the result variable the value your expecting? Can there be caching issues or issues with the browser prevent the redirect?
     
  7. Jizzler

    Jizzler

    Joined:
    Aug 10, 2007
    Messages:
    3,552 (1.25/day)
    Thanks Received:
    681
    Location:
    Geneva, FL, USA
    Don't see from a glance where it's failing, but a quick tip:

    PHP:
    if( !isset($_SESSION['LOGIN_STATUS']) ) {
        
    header('location:login.php');
        exit;
    }
    When using header() in this fashion you'll want to stop processing by exit. Header() will send an http header but the processing will continue and output sent to the requestor. In your example the worst is that you'll throw a undefined index notice ( echo $_SESSION['username']; ), but if you had somewhat important information information on that page it could be captured by anyone, not just those that have an account.
     

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page