how can i have phpbb set an additional cookie?

Discussion forum for MOD Writers regarding MOD Development.
BugDave
Registered User
Posts: 3
Joined: Tue Jan 22, 2008 10:28 pm

how can i have phpbb set an additional cookie?

Postby BugDave » Tue Jan 22, 2008 10:39 pm

I am trying to have phpBB set an additional cookie so i can track users by username with a php stats script called mint and it's plugin, secret crush. The problem is that I have yet to figure out how to do it on phpBB3. I had it working on phpBB2 by adding the following to the bottom of includes/page_header.php

Code: Select all

setcookie('phpbb_username', $userdata['username'], time() + 365 * 24 * 60 * 60, '/', $cookiedomain, false);


As this file doesn't exist in phpBB3 I am not sure what to do. I tried adding it to includes/session.php and includes/functions.php but had no luck. I even tried changing the string to the updated forum of

Code: Select all

setcookie('phpbb_username', $user->data['username'], time() + 365 * 24 * 60 * 60, '/', $cookiedomain, false);


but had no luck also. Any help would be greatly appreciated. TIA


Edit: added stats script name and url
Last edited by BugDave on Thu Jan 24, 2008 9:31 am, edited 2 times in total.

User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34418
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run
Contact:

Re: how can i have phpbb set an additional cookie?

Postby A_Jelly_Doughnut » Thu Jan 24, 2008 3:09 am

Includes/functions.php contains the page_header() function which takes over the duties that page_header.php had in phpBB2.

phpBB sets its cookies with its own method in the $user class. The usage should be apparent when you look at page_header() :)
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish

Celebrating 11 years as a phpBB user

BugDave
Registered User
Posts: 3
Joined: Tue Jan 22, 2008 10:28 pm

Re: how can i have phpbb set an additional cookie?

Postby BugDave » Thu Jan 24, 2008 8:55 am

Thank you. For anyone else who stumbles across this follow these directions:

open includes/functions.php
scroll down to the very end of the page_header function. It should look like this

Code: Select all

// application/xhtml+xml not used because of IE
   header('Content-type: text/html; charset=UTF-8');

   header('Cache-Control: private, no-cache="set-cookie"');
   header('Expires: 0');
   header('Pragma: no-cache');

   return;


Add this line to the empty space above "return;"

Code: Select all

setcookie('phpbb_username', $user->data['username'], time() + 365 * 24 * 60 * 60, '/', $cookiedomain, false);


It should look like this when you are done.

Code: Select all

   // application/xhtml+xml not used because of IE
   header('Content-type: text/html; charset=UTF-8');

   header('Cache-Control: private, no-cache="set-cookie"');
   header('Expires: 0');
   header('Pragma: no-cache');
        setcookie('phpbb_username', $user->data['username'], time() + 365 * 24 * 60 * 60, '/', $cookiedomain, false);
   return;



P.S. If you don't want to see anonymous users show up then insert this instead:

Code: Select all

if ($user->data['user_id'] != ANONYMOUS)
   {
   setcookie('phpbb_username', $user->data['username'], time() + 365 * 24 * 60 * 60, '/', $cookiedomain, false);
   }

mgoi
Registered User
Posts: 119
Joined: Sat Sep 01, 2007 10:55 am
Contact:

Re: how can i have phpbb set an additional cookie?

Postby mgoi » Wed Aug 27, 2008 9:42 am

Thanks very much Dave. That did the trick under phpbb3. I guess that the code for phpBB2 should be as follows:

Code: Select all

if ($userdata['user_id] != ANONYMOUS)
       {
       setcookie('phpbb_username2', $userdata['username'], time() + 365 * 24 * 60 * 60, '/', $cookiedomain, false);
       }


M

PS: sorry for posting 2.x info in a 3.x thread, but I thought it was more at its place here

Edit: I fixed the code above
Last edited by mgoi on Wed Aug 27, 2008 11:35 am, edited 1 time in total.

BugDave
Registered User
Posts: 3
Joined: Tue Jan 22, 2008 10:28 pm

Re: how can i have phpbb set an additional cookie?

Postby BugDave » Wed Aug 27, 2008 10:52 am

no problem :D

mgoi
Registered User
Posts: 119
Joined: Sat Sep 01, 2007 10:55 am
Contact:

Re: how can i have phpbb set an additional cookie?

Postby mgoi » Wed Aug 27, 2008 11:37 am

I am still having problems under phpBB2 with Secret Crush reporting "anonymous" users. I will report back on my experience when I will have finished my move to phpbb 3 but overall the nametags pepper works better than the secret crush pepper.

M


Return to “[3.0.x] MOD Writers Discussion”

Who is online

Users browsing this forum: cptwin and 31 guests