douren2831 2015-03-14 19:03
浏览 106
已采纳

IPB - 在IPB根目录之外访问成员数据PHP

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.

  • 写回答

1条回答 默认 最新

  • doushi1847 2015-03-14 21:09
    关注

    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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路