Welcome Guest, Not a member yet? Register   Sign In
Use WordPress Login plugin to automatically Login to a CI APP
#1

[eluser]Unknown[/eluser]
Hello All,

I'm am a newbie here so please be patient with my mistakes.

We have 2 environments. WordPress for main site and a custom CI App in /insuranceapp sub-folder.

The WordPress site uses Magic Members (MM) plugin to protect premium content. I need to have the MM login process trigger a CI App login. (The CI App uses the CI session class to store login info.)

I have been able to trigger the CI login by modifying the MM login and adding the following function: (I am a newbie coder so this might not even be the proper approach).

Code:
// I pass in login credentials from MM plugin here

function mgm_InsApp_Login($loginstuff){

$uid=$loginstuff['user_login'];
$pass=$loginstuff['user_password'];

// Build data to post to CI login routine.

$postdata = http_build_query(
  array(
   'email' => $uid,
   'password' => $pass,
   'user_login' => 'Login'
  )
);
$opts = array('http' =>
  array(
   'method'  => 'POST',
   'header'  => 'Content-type: application/x-www-form-urlencoded',
   'content' => $postdata,
  
  )
);
$context  = stream_context_create($opts);

// This is the URI of the CI login which authenticates and sets the logged in session cookie.

$result = file_get_contents(home_url().'/insuranceapp/index.php/common/login/check_login', true, $context);

echo ($result);

// For debugging to stop MM login and test for successful CI login session
exit();
}

The problem is, after the function runs I see the the successful CI login redirect to the users CI dashboard, but if I try to open any of the links on that page, it opens the CI login as if the user was never logged in. I suspect it has to do with the CI session cookie is not being written correctly or at all in the MM environment. Is this even the correct approach? I'll be happy to supply an other info.

Thanks in advance
#2

[eluser]Massaki[/eluser]
Check if the session class is loaded, and if the CI sessions are set:

Code:
$userdata = $this->session->all_userdata();
var_dump($userdata);
#3

[eluser]Unknown[/eluser]
Hi All,

Thanks for the response. It turns out the MM plugin, on the login, allows you to redirect the post data to any url. I just changed the redirect to point to the CI login routine and there captured the posted data (UID and password), then in the CI app built a form to automatically submit the (UID and password) post data back to the MM login url. Works great.

Thanks again.




Theme © iAndrew 2016 - Forum software by © MyBB