I’m trying to implement single sign-on. Don’t need to go into implementation details on that, but they want a BASE64 encoded JSON string of relevant user data. Like so:
<?php
$data = array(
"id" => "{logged_in_member_id}",
"username" => "{logged_in_username}",
"email" => "{logged_in_email}"
);
$message = base64_encode(json_encode($data));
?>Except. Even though EE is setting the info in the $data array correctly (i.e. [id] => “1”), when it’s base64’d, it’s encoding [id] => “{logged_in_member_id}” as a string literal.
Here’s a stripped down example code that I’ve found will work in any PHP-enabled template. I’ve tried on input and output (seems output should be the right one), but it doesn’t seem to make a difference.
<?php
$data = array(
"id" => "{logged_in_member_id}",
"username" => "{logged_in_username}",
"email" => "{logged_in_email}"
);
$message = base64_encode(json_encode($data));
print(json_encode($data) . "
");
print($message);
?>
If the base64 string matches this:
eyJpZCI6Intsb2dnZWRfaW5fbWVtYmVyX2lkfSIsInVzZXJuYW1lIjoie2xvZ2dlZF9pbl91c2VybmFtZX0iLCJlbWFpbCI6Intsb2dnZWRfaW5fZW1haWx9In0=
it decodes to this (not what I want) :
<!-- spaced out to prevent EE from interpreting -->
{"id":"{
logged_in_member_id
}","username":"{
logged_in_username
}","email":"{
logged_in_email
}"}This should be able to work, right? I’m on version 2.1.3. As a note, if you use the PHP base64_decode function and it decodes to {logged_in_username}, EE will interpret that and print the username. So I’ve been using a decoder website instead of the function.
Any help is much much appreciated. Thanks!