Examples - PHP - Account

Telldus Account Login Service

This example shows how to use Telldus Account Login Service to allow user to login using their Telldus account. We need the LightOpenID library for this example to work.

Walkthrough of the files:


First we must check if the user is already logged in. We will do this by checking the session variable:

if (isset($_SESSION['loggedin'])) { 

If the user is logged in, show our userĀ“s data:

    echo "<p>You are logged in!</p>";
"Telldus IDs: <b>" $_SESSION['telldus_id'] . "</b><br>";
"Email: <b>" $_SESSION['email'] . "</b><br>";
"Fullname: <b>" $_SESSION['fullname'] . "</b><br>";

Else, let the user login:

} else {
"You are not logged in. <a href='login.php'>Login</a>";


This file does the actual communication with Telldus OpenID provider server.

Create the LightOpenID object and tell it to use Telldus server as the provider.

$lightOpenID = new LightOpenID();
$lightOpenID->identity 'http://login.telldus.com';

To retrieve the users name and email we must tell the server we are interested in those values:

$lightOpenID->required = array('contact/email''namePerson');

Next, lets go through the "if" block in reverse order. The first time this page is loaded, redirect us for user authorization:

} else {
header('Location: '$lightOpenID->authUrl(true) );

If the authorization is unsuccessful, show this to the user:

} else if ($_GET['openid_mode'] == 'cancel') {
"Login canceled. <a href='index.php'>Go back</a>";

After a successful login the user will be redirected to the same page with the query variable 'openid_mode' set to 'id_res'.

Here, we retrieve the values we are interested in, saving it to the session and then returning to the first page:

if ($_GET['openid_mode'] == 'id_res') {
    if (
$lightOpenID->validate()) {
$data $lightOpenID->getAttributes();
$_SESSION['telldus_id'] = $_GET['openid_identity'];
$_SESSION['email'] = $data['contact/email'];
$_SESSION['fullname'] = $data['namePerson'];
$_SESSION['loggedin'] = true;
header('Location: index.php');
    } else {
"Validation failed! <a href='index.php'>Go back</a>";

That is all needed to be done to allow users to login using their Telldus accounts.