Hi,
I am facing a problem in transferring session.I am developing a website and I want to integrate a forum in the website.I need to take the session of the user from my website to the forum. Is there any way of transferring my session values to the forum.
Thanks in advance

What forum script is running on your site?

Actually I am using phpbb forum in my website and I want same user for the website as well as forum,is there any way through which I can transfer my session values of my website to the forum I have integrated.

Sure that's pretty easy I think... you can even let your user log in on either site. That is just my assumption of course. I did an integration with phpbb before, but it has been a while since. However, I still have the barebones of the script I wrote to integrate little application with the phpbb.

I am looking at a general log in function on the other section of your site, so that they don't have to really be in the forum logging in , and go to the other section of the site to just get validated through the prevailing session from the forum. How about if we do it like this..

On the other section of your site --> we create a log in script -> Upon submit of the form -> user gets validated on your phpbb log in sytem -> if a valid user, the user is then re-directed to the section of your site, where the login attempts was originatin from.

You can then modify the script as you like, but first I want you to see how the integration really works to have the complete view of what is really taking place. After this, you can definitely do whatever it pleases you.

NOTICES and ASSUMPTIONS: I am assuming here that your forum directory is located at YourDOMainDotCom/forum .. Of course you are free to modify the codes for your needs.

STEP ONE : copy codes below and save as other_page.php . This file will hooked on your phpbb authentication
FILENAME : other_page.php

<?php
    define('IN_PHPBB', true);
    $phpbb_root_path = './forum/';
    $phpEx = substr(strrchr(__FILE__, '.'), 1);
    include($phpbb_root_path . 'common.' . $phpEx);

    ## let start user session management
    $user->session_begin();

    $auth->acl($user->data);
    $user->setup();
    $user_sid = $user->session_id;
  if(($user->data['is_registered'])&&($user_sid !=''))
    ## if($user->data['session_logged_in'])
    ## if user is logged in we show them their username
  {
   ## echo the username of the logged in user  
   print $user->data['username'];

   ## we can also echo the user's session id by uncommenting below
    //echo "$user_sid <br/>";

   ## this is the area of the page where you want to show contents when logged.
   echo'<span class="brightgreen"> is logged in</span><br />
   <a title="See You Later" href="' . append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout', true, $user->session_id). '">Log out</a>';
   }
   else
   //user is not logged in 
   {
   ## offer members to log in with their forum account credentials OR give them the choice of registering 
    echo'You are not logged in<br /><a title="Log Yourself In" href="login.html">Log In</a> or
      <a title="Register" href="forum/ucp.php?mode=register"> Register</a>';
    }
    ?>

How to setup the script above... like I said on my lengthy introduction above, I am assuming that your forum is located in forum directory of your root directory, and this code reflects that assumption.
$phpbb_root_path = './forum/';

STEP TWO: Notice the codes above, I gave an option for the user to log in if they are not logged in forum or they are not coming from the forum?, assigned another page for the members to log in this part of the site. To make it work, we need to make a log in page just for this purpose.

Once again copy and save as login. html

FILENAME: login.html . I am not going to make this form a super fancy form. That is your job to make it aesthitically beutiful as you wished.

Please log in:<br />
  <form method="POST" action="./forum/ucp.php?mode=login">
  <p>Username: <input type="text" name="username" size="40"><br />
  Password: <input type="password" name="password" size="40"><br />
  Remember Me?: <input type="checkbox" name="autologin"><br />
  <input type="submit" value="Submit" name="login"></p>
  <input type="hidden" name="redirect" value="../other_page.php">
  </form>

If you user use this form, the log in credentials will be validated by the phpbb login function and then if it is a valid one, the user will be redirected back your othe_page.php as a logged and verified user.

This code "value = "../other_page.php" " a reference to the other_page.php as viewed by the phpbb coming from YourDomainDotCom/forum. So, you just have to very careful in setting this up. Please also take a note on the location of the form processor which is ./forum/ucp.php?mode=login.

Good luck and happy integration..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.