Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

phpBB2 - Access/Decoding cookies

Options
  • 26-04-2004 9:14pm
    #1
    Registered Users Posts: 68,317 ✭✭✭✭


    Hi guys, I'm adding phpBB2 to my site, and trying to integrate member functions into the index page (with the forums in a subdirectory), like boards.ie with its number of new messages, avatar etc. phpBB cookies look funny though, unlike vB, which has standard username/password cookies, phpBB seems to jam all the data into one cookie, encoded or serialized or something. I could spend all night trawling through source code and get nowhere :(

    Has anyone ever dealt with this? I know bazH has some experience with this kind of thing.... :p


Comments

  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Turns out the stripslashes() function, followed by unserialize() will reveal their innenr guts.

    Creates more questions than it answers though tbh :(


  • Registered Users Posts: 1,967 ✭✭✭Dun


    Okay, I'm afraid I don't have time to explain this more and strip out my CSS, but this is a simple php code that *should* read the cookie and if the user is logged in, get their login details (I wrote it so long ago I can't remember what I included - but read through it) and say hi you have PMs or not, and display their avatar. If not, it will present a small login box. It works fine on my forum, which is version 2.5 as far as I recall.


  • Registered Users Posts: 1,967 ✭✭✭Dun


    And here is one I wrote to show the last ten messages (works whether the user is logged in or not) from the message board, much like the boards.ie frontpage, including the [new] tag at the end of unreplied threads. Again, strip out the css, change your domain, and change the folder from /forum/ to whatever you have it installed in. As it's generic enough, it should work. *should* :)


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Oops, sorry didn't see these replies.

    I found out that you can use some of the scripts from phpBB to manage sessions/cookies and cookie authentication (to make sure someone hasn't tampered with their cookie), almost exactly as you can just post user data to the login script to log them on or off.

    That script for the last 10 posts will come in handy though. Cheers!


  • Registered Users Posts: 1,967 ✭✭✭Dun


    Now I'm not so busy, I had a look, and anyone using the first script needs this first part, courtesy of the phpBB crew:
    [php]
    define('IN_PHPBB', true);
    $phpbb_root_path = './relative_or_absolute_SERVER_path_to_forum';
    @include($phpbb_root_path . 'extension.inc');
    @include($phpbb_root_path . 'common.'.$phpEx);

    //
    // Start session management
    //
    $userdata = session_pagestart($user_ip, PAGE_INDEX);
    init_userprefs($userdata);[/php]

    And the version of the "last ten posts" needs altering:

    This is the proper version

    [php]<?php
    include("conexion.inc");

    $connection = mysql_connect($host,$user,$password)
    or die("Failed to establish connection to database server");
    $db = mysql_select_db($databasename,$connection)
    or die("Failed to connect to selected database");
    $query2 = "SELECT phpbb_topics.topic_title,
    phpbb_topics.topic_replies, phpbb_topics.topic_id, phpbb_topics.topic_last_post_id,
    phpbb_posts.post_id, phpbb_posts.poster_id, phpbb_posts.post_time, phpbb_posts.forum_id,
    phpbb_forums.forum_id,phpbb_forums.forum_name, phpbb_users.username
    FROM phpbb_topics,phpbb_posts,phpbb_forums,phpbb_users
    WHERE phpbb_topics.forum_id != '7'
    AND phpbb_topics.topic_last_post_id = phpbb_posts.post_id
    AND phpbb_posts.forum_id = phpbb_forums.forum_id
    AND phpbb_posts.poster_id = phpbb_users.user_id
    ORDER BY phpbb_posts.post_time
    DESC LIMIT 0,10";
    $result2 = mysql_query($query2)
    or die("Failed to execute query 2");

    while ($row2 = mysql_fetch_array($result2))
    {
    extract($row2);
    if ($topic_replies == 0)
    { $topic_length = strlen($topic_title);
    if ($topic_length >= 30 )
    {
    $topic_chomp = substr($topic_title,0,29);
    $topic_short = $topic_chomp."… [new]";
    }
    else
    {
    $topic_short = $topic_title." [new]";
    }
    }
    else
    {
    $topic_length = strlen($topic_title);
    if ($topic_length >= 36 )
    {
    $topic_chomp = substr($topic_title,0,34);
    $topic_short = $topic_chomp."…";
    }
    else
    {
    $topic_short = $topic_title;
    }
    }
    echo "<tr>";
    echo "<td nowrap><a href=\"http://www.DOMAIN.com/FORUM/viewforum.php?
    f=$forum_id\">$forum_name   </a></td>";
    echo "<td nowrap><a href=\"http://www.DOMAIN.com/FORUM/viewtopic.php
    ?t=$topic_id\" title=\"$topic_title\">$topic_short   </a></a></td>";
    echo "<td nowrap><a href=\"http://www.DOMAIN.com/FORUM/profile.php?
    mode=viewprofile&u=$poster_id\">$username   </a></td>";
    $post_day = date("d",$post_time);
    $post_month = date("M",$post_time);
    $post_year = date("Y",$post_time);
    $post_time = date("H:i",$post_time);
    echo "<td nowrap>$post_day</td>";
    echo "<td nowrap>$post_month</td>";
    echo "<td nowrap>$post_year</td>";
    echo "<td nowrap>$post_time</td>";

    echo "</tr>";
    }
    ?>[/php]

    I made the date a bit more detailed, so you might want to cut that back (though if you delete the <td> change the colspan from the first two rows.

    Both scripts are working well with phpBB 2.0.8a


  • Advertisement
Advertisement