PHP example for page using session login

Andy Simpson Posted in General Discussion 3 years ago

I wanted to host an external PHP page in my OSSN document root, linked to from OSSN, but also authenticated using the OSSN session data. I needed to be able to do things not available using custom pages.

Here is how I did it (working source).

Put this at the top of your external page. If they are logged into OSSN, they will be able to access it. If they are not logged into OSSN, they will be returned to your OSSN login page.

I would not rely on this working through future upgrades or new versions though.

<?php

session_start();

if (empty($SESSION["OSSNUSER"])) {
header('Location: http://www.your_ossn_url.com/login');
}

$sessiondata = $SESSION;

$sessiondata = jsondecode(jsonencode($sessiondata), true);

$guid = $sessiondata['OSSNUSER']['guid'];
$firstname = $sessiondata['OSSNUSER']['firstname'];
$lastname = $sessiondata['OSSNUSER']['lastname'];

?>

Replies
au Andy Simpson Replied 3 years ago

Note, there is an underscore between OSSN and USER, not visible here. And there is an underscore between $ and SESSION also.

Premium Version

Due to the many requests in the past for additonal features and components we have decided to develope a premium version. Features like Hashtags, Videos, Polls, Events, Stories, Link Preview, etc included in it.

$199 (Life Time)
Learn More

Other Questions