Integrate Elgg into an existing PHP application

Hi,
I am new to Elgg. I am trying to integrate Elgg into my existing PHP application. Both application(Elgg and existing app) will be hosted in the same server under same root folder. I am planning to use existing application as master and Elgg as slave. User validation and registration will be done through existing app as it is being done now. A link will be provided for Elgg in the menu of existing app. I am looking for best possible ways to:

1. open Elgg app from existing app via link. I wrote a new login plugin to unregister current login action and use new login event to read username from session variable saved by existing app. But Elgg is not recognizing the session value stored by existing app. Don't know what is the problem. I guess, I have use same session for both app. Is there any easy way to access session used by Elgg from existing app and set values to be used by new login event?

2. load user into Elgg database from external app when new user account is created(currently I am loading users onto Elgg database manually using the upload_user plugin)
Hope someone please help me. Thank you.

  • I looking for ways to add external app logic to system boot event without touching core code?Is that possible?

  • I had similar problem some hours ago. i had to change "Elgg / engine / lib / sessions.php" to an updated version found at
    "https://github.com/sroutier/Elgg/blob/41024e1f2c7a9dd49c9c232aff31868850ecd3e5/engine/lib/sessions.php" and it worked perfectly for me
    The updated version adds UUID to session and cookie name to avoid conflict between the elgg session and the parent app session.
    Though elgg's core file "sessions.php" is being changed, it is a good solution if don't mind the change.

  • Thanks Don for sharing this with me. I will try your solution today. If I don't have any choice, I ok with changing core files.

  • Don - your solution didn't work for me..anyway, I found a work-around solution.

    Thanks everyone for the suggestions.

  • Hello Nambi, Pamwel, Don G,

    I'm a bit confused here.
    I am about to try what you guys mentionen above with an app done via POG but somethings are not that clear for me.

    If I understood correct I have to go ahead with the following steps:

    1. Install elgg on a subfolder of the app.
    2. Be sure that the app controls the session handlers via DB as in elgg.
    3. Authenticate the user via elgg API.
    4. Update the "sessions.php" original file (the one created during installation) with the "sessions.php" updated  (from github).
    5. If the 4th step didn't work at the end have to go trough a workaround sollution... (Which one?)

    At the end how did you do to integrate your APP?

    Has anyone suceed with this integration?

    Thanks in advance 

    Remember, if you ever need a helping hand, you'll find one at the end of your arm. . . As you grow older you will discover that you have two hands. One for helping yourself, the other for helping others

  • Hello German,

    I just did the following steps to integrate two apps.............
    1) I put the link on the 1st app to redirect on to 2nd app...
         eg. <a href="../../social/index.php?ses=<?php echo $userid=$_SESSION['DUSER_ID'];?>" target="blank"> Social & Collaborative </a>

    Description:-- Here, I have redirected a user to the 2nd app through this link and I have passed the session variable(which contains username[unique identification of user]) as a query string on the index page of the 2nd app...so that I can use the session of 1st app on to the 2nd app...

    2) I have just used the passed session variable on the index page of the 2nd app on which I have passed it just below the line,
                         require_once(dirname(__FILE__) . "/engine/start.php"); 
    And check for the login procedure on the base of the existance of that particular session variable as given below..
       
    eg......
    require_once(dirname(__FILE__) . "/engine/start.php");

    global $SESSION;
    $SESSION['username']=$_REQUEST['ses'];
    if(isset($SESSION['username']))
    {
        $username = $SESSION['username'];
        $user = get_user_by_username($username);
        //$forward_url='';
        try {
        login($user, $persistent = false);
        }catch (LoginException $e) {
        register_error($e->getMessage());
        forward(REFERER);
        }
        system_message(elgg_echo('loginok'));
        forward('dashboard');
        
    }
    Description:-- Here, I have redirected a user on the dashboard of his/her own after he/she got authorized as logged in..

    Moreover, I have mapped the users' details of the 1st app with the 2nd app...So that it will check for the same username that was passed from the 1st app in to the 2nd app.....and if it will get then the user will directly get logged in without putting any credentials....

    Hope you will get a little bit idea of the way I did it...

  • Hi Parixit,

    This not just save me up a lot of time but also showed me what I was doing wrong before, I followed your instructions but got stocked in a point on the session handling I guess due to the PHP version (PHP-FCM not PHP)...

    Anyway, I am working on it and I wanted to thank you for your kind reply.

    I'll talk back to the comunity as soon as I get trough this...

  • Hi German,

    I know its not your complete solution. And for session it will be different for both yours and ELGG.

    Because ELGG is using .htaccess and so that session is different for the directory of ELGG. I am also having same issue, so I made a changes that I connect both using token so user logged in your application will goes to ELGG with token and we verify it and initialize the session.

    Hope this helps you.

Beginning Developers

Beginning Developers

This space is for newcomers, who wish to build a new plugin or to customize an existing one to their liking