1

can you help me writing this lines of code for grab in a EE template the information about a logged_in user, using php.

I'm using Vanilla Forum, and i want to use the JsConnect to pass the logged_in user information to the Vanilla Log in. Here's the guide:

Implementing Vanilla jsConnect Single-Signon on your Site

I found that libraries to include in system

PHP jsConnect client library

And the code to include in my page template is this:

<?php
require_once dirname(__FILE__).'/functions.jsconnect.php';

// 1. Get your client ID and secret here. These must match those in your jsConnect settings.
$clientID = "1234";
$secret = "1234";

// 2. Grab the current user from your session management system or database here.
$signedIn = true; // this is just a placeholder

// YOUR CODE HERE.

// 3. Fill in the user information in a way that Vanilla can understand.
$user = array();

if ($signedIn) {
   // CHANGE THESE FOUR LINES.
   $user['uniqueid'] = '123';
   $user['name'] = 'John PHP';
   $user['email'] = 'john.php@anonymous.com';
   $user['photourl'] = '';
}

// 4. Generate the jsConnect string.

// This should be true unless you are testing. 
// You can also use a hash name like md5, sha1 etc which must be the name as the connection settings in Vanilla.
$secure = true; 
WriteJsConnect($user, $_GET, $clientID, $secret, $secure);

How can i call the logged_in user info here

// 2. Grab the current user from your session management system or database here.
$signedIn = true; // this is just a placeholder

// YOUR CODE HERE.

with this

{if logged_in}
UniqueID={member_id}
Name={username}
Email={email}
PhotoUrl={photo_url}{photo_filename}
{/if}

And assign that the variables to pass to

// 3. Fill in the user information in a way that Vanilla can understand.
$user = array();

if ($signedIn) {
   // CHANGE THESE FOUR LINES.
   $user['uniqueid'] = '123';
   $user['name'] = 'John PHP';
   $user['email'] = 'john.php@anonymous.com';
   $user['photourl'] = '';
}

To generate a json file that vanilla JsConnect can read?

I think also

<?php
require_once dirname(__FILE__).'/functions.jsconnect.php';

return error in ExpressionEngine

Please somebody can tell me how can solve this.

Thank you in advance Alessio

1

If this is in a template you can just use: {member_id} {username} {email}

If you want to use all php you can use the Session class: http://ellislab.com/expressionengine/user-guide/development/usage/session.html

$user['uniqueid'] = $this->EE->session->userdata('member_id');
$user['name'] = $this->EE->session->userdata('username');
$user['email'] = $this->EE->session->userdata('email');

You'd probably be better off writing an extension that takes care of this at login than in a template.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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