0

Iam making my own custom login in wordpress using wp_signon function. Whenever a user enters his credentials, another page is called using ajax. In that page, i check the users credentials, and log the user in using wp_signon function. Then a confirmation is sent and the current page captures it and displays that the user is successfully logged in. The code works in Chrome and Firefox but doesnot work in IE. This is the code in the AJAX file. The current page gets a response saying the user is logged in, but when i refresh it still shows the user is not logged in. :( stuggling with it for days. Help me please

$creds = array();
$creds['user_login'] = $user;
$creds['user_password'] = $password;
$creds['remember'] = $remember;
$user = wp_signon( $creds, true );
if ( is_wp_error($user) ){
    echo "Invalid Username or Password";
}
else {
    $current_user = wp_get_current_user();
    $userid=$current_user->ID;
    mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
    $dbquerry= 'select `login` from wp_users where user_login="'.$_GET['user'].'"';

    $result=mysql_db_query($dbname,$dbquerry);
    list($login)=mysql_fetch_array($result);
    if($login==1) {
        echo "change";
    }
    else {
        echo "success";
    }
}

This code work well in Chrome and firefox and not in IE

6
  • Have you thought to look at your JavaScript? I single comma on an array will cause a JS error. Also a little more information on your WP AJAX hooks etc is always useful.
    – Cristian
    Jul 24, 2012 at 20:32
  • I didnt use any wp AJAX hooks as this is an external page extending wordpress functions. And the Javascript works fine. If i enter the right credentials it receives success. But when i refresh the page, the user is not logged in. Jul 24, 2012 at 20:37
  • Had you tried to look of any errors using IE browser debugger? It in that case you will know what is wrong with your js script.
    – tiltdown
    Jul 24, 2012 at 23:03
  • 1
    IE, making the life worse since 1995!
    – brasofilo
    Jul 25, 2012 at 8:39
  • 1
    Finally found out the culprit and solved the problem :) IE caches AJAX requests. So whenever you use AJAX call to set login cookies, you are in for a trouble in IE. Beware!!!!! In your ajax call fill in a random number in the URL so that IE wont catch Jul 25, 2012 at 19:27

1 Answer 1

2

Finally found out the culprit and solved the problem :) IE caches AJAX requests. So whenever you use AJAX call to set login cookies, you are in for a trouble in IE. Beware!!!!! In your ajax call fill in a random number in the URL so that IE wont catch

In the Ajax call inserted this

    var d = new Date();
    var n = d.getTime();
    req.open("GET", "something.php?user"+username+"&x="+n);

By doing this IE wont cache the AJAX request

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.