I have a site that has a Wordpress blog section. I would like to enable Single Sign On in the site so that on logging onto my site, the WP blog also logs on on simultaneously. I have two user tables. One for the site, other for the WP part. What I did was add a curl along with the function for logging on the site's blog section. Below is the code that I had used.

$username = $_POST['username'];
    $password = $_POST['password'];

        $postdata = "log=". $username ."&pwd=". $password ."&wp-submit=Log%20In&redirect_to=". $url ."wp-admin/&testcookie=1";
        $ch = curl_init();
        curl_setopt ($ch, CURLOPT_URL, $url . "wp-login.php");
        curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070725 Firefox/");
        curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
        curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
        curl_setopt ($ch, CURLOPT_REFERER, $url . "wp-admin/");
        curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
        curl_setopt ($ch, CURLOPT_POST, 1);
        $result = curl_exec ($ch);

Thing is that the wp_signon() function is getting the values but it doesn't seem to be generating the required cookie. What changes are to be made to get the cookie generated.

I had tried another method where I hard coded the values into the wp_login.php page. Here I had set the values into the $creds array.


But that prevented logging out from the blog. So that plan didn't work out.

Some help would be nice. Thanks in advance.

2 Answers 2


Take a look at this answer and see if it help:


  • I require the admin to be logged in to the WordPress blog
    – Shyam K
    Commented Jul 18, 2012 at 6:29
  • There are no other users there. Also why use the email address? Can't we just use the admin username 'admin' ? Plus, I don't want to create other users.
    – Shyam K
    Commented Jul 18, 2012 at 6:40
  • @ShyamK if you have no users, why do you want to do SSO? That makes no sense. Just login to your WP install, make sure you have cookies enabled, and tick the "remember me" box
    – anu
    Commented Jul 18, 2012 at 7:43
  • Let me make this clear. I have a single user, the admin. No one else. I don't want to have any more users on the WP page either. Just the 'admin' alone will do fine. But I want to (kind of) disable that log-in page, so that the admin can click on the blog link and just directly go to the admin panel of the WP blog. The admin of my site must never see the log in page of the wordpress blog.
    – Shyam K
    Commented Jul 18, 2012 at 10:00
  • Also logging out from WP must also log out my site.. Thats kind of the plan
    – Shyam K
    Commented Jul 18, 2012 at 10:02
    $username = $_POST['username'];
    $password = $_POST['password'];

    define('__ROOT__', dirname('public_html'));
    require_once (__ROOT__.'/blog/wp-load.php');

    $credentials = array('user_login' => $username, 'user_password' => $password);
    $user  = wp_signon($credentials,$secure_cookie);

This is the code that I placed immediately after my site log-in was validated. What this basically does is include the wp-load.php file, which in turn allows me to make WP function calls from my site. So I call the wp_signon( ) function passing along the posted values from my site.

Please note this method only works if the username and password of both the the site and WP blog are the same. This is not a proper method for WP Single Sign On, just a hack that worked in my case

I had later disabled the option of changing the password on the admin panel.

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.