Standard phpBB-session handling with own coding page

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
RobiX
Registered User
Posts: 97
Joined: Thu Oct 05, 2017 9:59 am

Standard phpBB-session handling with own coding page

Post by RobiX » Sat Dec 09, 2017 5:17 pm

I created a custom coding page in phpbb, e.g., see also https://www.phpbb.com/support/docs/en/3 ... tegration/

Now I have the problem that i can't share session variables between phpBB and the new page.

index.php

Code: Select all

$user->data['newvar'] = "index.php";
ownpage.php

Code: Select all

$user->session_begin();
echo $user->data['newvar']; //empty/null <------ why not index.php?
$user->data['newvar'] = "ownpage.php";
echo $user->data['newvar']; //of course: ownpage.php
$auth->acl($user->data);

Code: Select all

$user->session_begin();
Above line starts a totally new session or not? Maybe that's the reason for it - i tried also

Code: Select all


if (isset($user)) {
//already set
} else {  //not set - so start a new session
  $user->session_begin();
}
... in both files - but doesn't work too :(

User avatar
Elias
Registered User
Posts: 4616
Joined: Sat Feb 25, 2006 4:31 pm
Location: In the Water!
Name: Elias
Contact:

Re: Standard phpBB-session handling with own coding page

Post by Elias » Sun Dec 10, 2017 1:30 am

Step 2 of that article explains what you need.

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();
Must be on top of every new file you make.
*modify the forum’s root path to where you got phpBB installed.
"Mystery creates wonder, and wonder is the basis of man's desire to understand." - Neil Armstrong
|Installing Extensions|Writing Extensions|Extension Validation Policy|

RobiX
Registered User
Posts: 97
Joined: Thu Oct 05, 2017 9:59 am

Re: Standard phpBB-session handling with own coding page

Post by RobiX » Sun Dec 10, 2017 2:31 am

Hi Elias, tnx for your reply:

Every own file includes this header. my own files are in the same directory as index.php (phpbb).

BOARD_URL variable shows http://localhost/test.
But I set phpbb_root_path= "./" because http://localhost/test doesnt work ("failed to open stream: No such file or directory").

So I guess the variables are correctly set (and own pages are correctly shown without errors).

:( But exchange of session variable doesnt work :(
Last edited by RobiX on Mon Dec 11, 2017 7:07 am, edited 1 time in total.

RobiX
Registered User
Posts: 97
Joined: Thu Oct 05, 2017 9:59 am

Re: Standard phpBB-session handling with own coding page

Post by RobiX » Sun Dec 10, 2017 2:38 am

Even when I write the below lines in the original forum file index.php nothing changes ...

IMHO after the first set, the newvar variable should be always set to "index.php".

Code: Select all

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

echo "before: (".$user->data['newvar'].")"; //in the beginning empty
                                         //when next click on link to index.php, it is empty again
                                        //(and variable is not set to "index.php")!
$user->data['newvar'] = "index.php";
echo "after: (".$user->data['newvar'].")";
Output
before: ()
after: (index.php)

(next click on the link to the form = index.php)

before: ()
after: (index.php)

...
Last edited by RobiX on Mon Dec 11, 2017 7:05 am, edited 1 time in total.

RobiX
Registered User
Posts: 97
Joined: Thu Oct 05, 2017 9:59 am

Re: Standard phpBB-session handling with own coding page

Post by RobiX » Mon Dec 11, 2017 6:58 am

ping ;)

User avatar
AmigoJack
Registered User
Posts: 5386
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Standard phpBB-session handling with own coding page

Post by AmigoJack » Mon Dec 11, 2017 8:54 am

phpBB doesn't support the concept of session "variables" - you either have to use cookies or your own database table. If you would have looked at print_r( $user-> data ); to being with you would have realized it doesn't have any data which is magically stored to the database again at some point.
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.

Post Reply

Return to “phpBB Custom Coding”

Who is online

Users browsing this forum: No registered users and 4 guests