wordpresssingle-sign-onphpbbreferer

Allowed to access a restricted page when redirected from a certain site


I have a phpbb forum (eg. forum.domain.com) and a Wordpress site (accounts.domain.com).

The forum login and registration is handled by Wordpress via SSO.

There are 2 registration pages:

  1. http://accounts.domain.com/forum-register/
  2. http://accounts.domain.com/registration/

The first link is specific and restricted for the forum only and I only want users clicking the Register link on forum.domain.com access the first page while other users trying to access the first page gets redirected to the second page.

Is there any way to achieve this?


Solution

  • You could use $_SERVER variable to check the referer and make decision.

    Code:

    <?php
    
    $referrer = $_SERVER['HTTP_REFERER'];
    if ( $referrer != 'http://forum.domain.com' ) {
    
        header( 'Location: http://accounts.domain.com/registration/ ' ) ;
    
    } 
    
    ?>
    

    This code will check the referer, if user is not coming from http://forum.domain.com then it will redirect to normal registration page.

    This code should be placed on forum registration page.

    Hope it helps! :)