Search code examples
phpipb

IPB - Access member data PHP outside IPB root


I have IPB and I have an PHP application which is outside of forum ROOT and on another subdomain as well.
In application I need to have access to member data, eg. posts count, email etc.

I have the latest IPB version and PHP 5.6
I googled a lot for solution, and finally I found this one: Accessing IPB Classes Externally From Main Website
However, it didn't worked at all. There is no errors, just redirection to main forum URL.

Does anybody have experience wit IPB classes and or it's API? Can somebody help me to reach the goal.
Solution is probably just one line of code.

EDIT: I found work around, check out my answer below.
However I'm still interested for "nicer" solution.


Solution

  • After some research, I configured out that IPB redirects because board url doesn't match with current URL/subdomain. (my case)
    So... There is workaround, not so nice but works at least, and is one-line solution:

    <?PHP
    $_SERVER['HTTP_HOST_R'] = $_SERVER['HTTP_HOST']; // Keep original info in another index.
    $_SERVER['HTTP_HOST'] = "www.your-ipb-forum.com"; // Work-around
    $forumPath = '../forum'; //FORUM FOLDER
    define( 'IPS_ENFORCE_ACCESS', TRUE ); // Important so it does not redirect to forums
    define( 'IPB_THIS_SCRIPT', 'public' );
    
    require_once( $forumPath.'/initdata.php' );
    require_once( IPS_ROOT_PATH . 'sources/base/ipsRegistry.php' );
    require_once( IPS_ROOT_PATH . 'sources/base/ipsController.php' );
    
    $ipbRegistry    = ipsRegistry::instance();
    $ipbRegistry->init();
    // Init done
    
    $member = IPSMember::load($memberName, 'all', 'username');
    print_r($member); // For demo purposes only
    

    The third line is work-around with which we cheat on IPB.
    The second line is "moving" $_SERVER['HTTP_HOST'] data to $_SERVER['HTTP_HOST_R'] so if you need current(real) URL in your application, you may use this variable instead because HTTP_HOST one is changed. (needed for workaround).