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.

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'];
    $url="http://www.crickees.svn.local/blog/";
        $cookie="cookie.txt";

        $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:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
        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);
        curl_close($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.

wp_signon($creds,$secure_cookie);

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

Some help would be nice. Thanks in advance.

share|improve this question
add comment

2 Answers 2

up vote 0 down vote accepted
    $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.

share|improve this answer
add comment

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

http://wordpress.stackexchange.com/a/11472/490

share|improve this answer
    
I require the admin to be logged in to the WordPress blog –  Shyam K Jul 18 '12 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 Jul 18 '12 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 Jul 18 '12 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 Jul 18 '12 at 10:00
    
Also logging out from WP must also log out my site.. Thats kind of the plan –  Shyam K Jul 18 '12 at 10:02
show 1 more 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.