Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
    
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 '12 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. –  Thirukumaran Nagarajan Jul 24 '12 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. –  wpleet Jul 24 '12 at 23:03
1  
IE, making the life worse since 1995! –  brasofilo Jul 25 '12 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 –  Thirukumaran Nagarajan Jul 25 '12 at 19:27
show 1 more comment

1 Answer

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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