phpbb检查用户是否登录自定义php页面

时间:2014-04-22 15:11:08

标签: php phpbb phpbb3

我正在运行一个私人phpbb 3.0.12论坛,并链接到一个名为videochat.php的页面,该页面有一个连接到rtmfp服务器的flash页面。我想确保访问videochat.php的人登录并注册(除了访客之外的任何访问级别),否则它会将其重定向到www.domain.com。如果会员已注册,我想要一个名为$ videochatusername set的变量。谢谢!

videochat.php(从论坛链接到此页面) - > domain.com/forum/videochat.php 论坛根目录 - > domain.com/forum /

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

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

if ($user->data['user_id'] == ANONYMOUS)
{
echo('NOT LOGGEDIN');
}
else{
include($phpbb_root_path.'config.'.$phpEx);

// test echo
echo $user->data['username'];

?>

2 个答案:

答案 0 :(得分:0)

您的代码已接近正常运行。试试这个:

if ($user->data['username'] == 'Anonymous')
{
    // User is not logged in/registered
    // Your redirect code can go here if you haven't output anything to the browser
}

区别在于'Anonymous'被引号括起来而不是常量,就像你的代码一样。

如果您向此else添加if阻止,则可以设置$videochatusername变量

else
{
    $videochatusername = $user->data['username'];
}

答案 1 :(得分:0)

在phpBB 3.3.2中:

<!-- IF S_USER_LOGGED_IN -->
     ...do something...
     ...you can even run php by this...
<!-- ELSE -->
     ...if user is not logged in...
<!-- ENDIF -->