Page 1 of 2

When user register in phpBB, can be added at same time into WP?

Posted: Tue Jan 16, 2018 6:21 pm
by axew3
When a user signs up to the phpBB, is a wordpress user profile automatically
created for them?
This is the original question via email received, which i would answer as hint for all here, and as suggestion for a trick that will be added on next versions.

The answer is No, but could also be Yes. Let explain.

No because this is a WP plugin, then the code run only on WP side. If an user register in phpBB, no code is execute in WP side, until user not load a WP page, and so will be added also into WP.
At same time, could be achieved with a snippet of php code, in many flavors, that can be executed by phpBB when user register. But you have to add this code into phpBB, that will provide to create the user in WP database also.

But the answer is also Yes (+- at same time) if you use a trick and this plugin:
1) a php code, that force redirecting the user to WP, when login is done phpBB (so if it has not still added into WP, will be added).
2) or a JS code applied into some template file (may overall_header.html, or overall_footer.html) that should do the same (redirect to WP the user after the login in phpBB).

In WP_w3all iframe mode, this concept is applied with the JS trick that you can see in action: if an user login in phpBB, the WP page reload because a JS code is executed to detect phpBB login/out state of user.

But is possible to do some more. Also without iframe. Via JS or Php.
A simple code in phpBB, let say maybe javascript, that redirect the user to WP when login is done, appending one or more vars: when the WP page will load detecting these vars, could add the user in WP on fly, because the plugin will found a valid phpBB cookie, so the user addition in WP will fire: due to detected vars, after user has been added, and before WP will go to output, could be so redirected from where he was coming from, so in phpBB.
This trick is more hard to explain in words than to be coded.
It is the same concept (that already work) for the registration/login done in phpBB via iframed WP page.

Will be added something about it (Js version) for the phpBB overall_footer.html code on next plugin versions.
And a simple snippet to redirect in same way, with same result, but using php, so will be possible to use one or other (php more reliable, because on this, will work in any case).
The plugin will add instead the simple php code, that will answer doing tasks (adding user and redirecting to forum) in the right way, when passed vars will be detected.

Re: When user register in phpBB, can be added at same time into WP?

Posted: Thu Jan 25, 2018 3:48 am
by azik1
Can please post the code snippet for redirect to Wordpress I would really appreciate it thanks in advance

Re: When user register in phpBB, can be added at same time into WP?

Posted: Thu Jan 25, 2018 6:21 pm
by axew3
I would really appreciate it thanks in advance
Is obscure what's the meaning of this, most of the time :D

To detect redirect from a login, as on this case, in phpBB, may can be achieved checking the protected object redirect and redirect the user only in this case, in this way:

open: includes/functions.php
search for:

Code: Select all

function redirect($url, $return = false, $disable_cd_check = false)
{
	global $user, $phpbb_path_helper, $phpbb_dispatcher;
just after this, add the follow, changing the correct URL that point to your WordPress:

Code: Select all

global $request;
   $mode = $request->variable('mode', '');
    if($mode == 'login' ){
      header("Location: http://www.my-nice-wp.com/"); 
    exit;
   }
when user login, will be then redirected to the assigned URL on the function header, and after phpBB logged in cookies have been released: so if WP_w3all will be active, the user will be added on fly also into WordPress.

The Javascript code to achieve this is even more easy, but i suppose for consistence, you may prefer this php way.

Re: When user register in phpBB, can be added at same time into WP?

Posted: Sun Jan 28, 2018 8:17 pm
by azik1
thanks for the peace of code

Re: When user register in phpBB, can be added at same time into WP?

Posted: Sun Jan 28, 2018 8:30 pm
by axew3
This +- will be the definitive code added on documentation as i can. It still lack maybe of a simple addition: a var to detect if the coming redirect fired by this code (so recognized after in WP, for the redirect), isn't a request done by iframed phpBB (in case it is used also), but full not iframed.
Then will be really complete.

Code: Select all

// START w3all redirect to WP onlogin
	// Note: this snippet code on this redirect() function should not be used (added) if using iframe mode -> will be removed this on definitive snippet
	// see class.wp.w3all-phpbb.php -> // START w3all redirect to phpBB (onlogin to add user in WP)
	// Note: the passed URL to redirect to, is not containing the string portion after '&sid=' that is cut off
	// Note: If you want pass also phpBB sid on URL (because phpBB login work also without cookie active on browser, using sid) maybe you'll remove the line more below where 'REMOVE this line'
	
	
	// DO NOT ADD FINAL SLASH
	$wordpress_url = 'http://localhost/wp49'; // SET HERE the WordPress URL you want to point to - DO NOT ADD FINAL SLASH (or change the code below)
	//
	 global $request;
    if( $request->variable('mode', '') == 'login' ){
     $rurl = stristr(htmlspecialchars_decode($url), '&sid=', true); // 'REMOVE this line' to pass entire URL (with also sid var included) // stristr as of PHP 5.3.0 or > 
     if( strpos($rurl, '/') == 0 ){ $rurl = trim(substr($rurl, 1)); }
     $rurl = base64_encode(generate_board_url() . '/'. str_replace('./', '', $rurl));
     header("Location: $wordpress_url/?w3allAU=$rurl"); 
    exit;
   }
// END w3all redirect to WP onlogin

Re: When user register in phpBB, can be added at same time into WP?

Posted: Sun Jan 28, 2018 10:16 pm
by azik1
so this a newer version of the first response or its an addon to the code that you posted last week?