我有一个主页+ xenforo论坛。 如果他登录,我想在主页上显示用户信息。
我找到了这个很棒的代码:
<?php
define('XF_ROOT', 'forums/'); // set this (absolute path)!
define('TIMENOW', time());
define('SESSION_BYPASS', false); // if true: logged in user info and sessions are not needed
require_once(XF_ROOT . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader(XF_ROOT . '/library');
XenForo_Application::initialize(XF_ROOT . '/library', XF_ROOT);
XenForo_Application::set('page_start_time', TIMENOW);
XenForo_Application::disablePhpErrorHandler();
XenForo_Application::setDebugMode(false);
if (!SESSION_BYPASS)
{
XenForo_Session::startPublicSession();
$visitor = XenForo_Visitor::getInstance();
if ($visitor->getUserId())
{
$userModel = XenForo_Model::create('XenForo_Model_User');
$userinfo = $userModel->getFullUserById($visitor->getUserId());
}
}
restore_error_handler();
restore_exception_handler();
?>
这对我来说就是这样。 然后我做了
的var_dump($用户信息);
它给了我这个大阵容:
array(61) { ["user_id"]=> int(1) ["username"]=> string(4) "Jony" ["email"]=> string(20) "artemkller@gmail.com" ["gender"]=> string(0) "" ["custom_title"]=> string(0) "" ["language_id"]=> int(1) ["style_id"]=> int(0) ["timezone"]=> string(13) "Europe/London" ["visible"]=> int(1) ["user_group_id"]=> int(2) ["secondary_group_ids"]=> string(3) "3,4" ["display_style_group_id"]=> int(3) ["permission_combination_id"]=> int(7) ["message_count"]=> int(0) ["conversations_unread"]=> int(0) ["register_date"]=> int(1362857171) ["last_activity"]=> int(1362949375) ["trophy_points"]=> int(1) ["alerts_unread"]=> int(0) ["avatar_date"]=> int(0) ["avatar_width"]=> int(0) ["avatar_height"]=> int(0) ["gravatar"]=> string(0) "" ["user_state"]=> string(5) "valid" ["is_moderator"]=> int(1) ["is_admin"]=> int(1) ["is_banned"]=> int(0) ["like_count"]=> int(0) ["warning_points"]=> int(0) ["dob_day"]=> int(0) ["dob_month"]=> int(0) ["dob_year"]=> int(0) ["status"]=> string(0) "" ["status_date"]=> int(0) ["status_profile_post_id"]=> int(0) ["signature"]=> string(0) "" ["homepage"]=> string(0) "" ["location"]=> string(0) "" ["occupation"]=> string(0) "" ["following"]=> string(0) "" ["ignored"]=> string(0) "" ["csrf_token"]=> string(40) "9fe480c5ed5a27d3a888a1ec6e1f4fa2c0109db4" ["avatar_crop_x"]=> int(0) ["avatar_crop_y"]=> int(0) ["about"]=> string(0) "" ["facebook_auth_id"]=> int(0) ["custom_fields"]=> string(0) "" ["show_dob_year"]=> int(1) ["show_dob_date"]=> int(1) ["content_show_signature"]=> int(1) ["receive_admin_email"]=> int(1) ["email_on_conversation"]=> int(1) ["is_discouraged"]=> int(0) ["default_watch_state"]=> string(0) "" ["alert_optout"]=> string(0) "" ["enable_rte"]=> int(1) ["allow_view_profile"]=> string(8) "everyone" ["allow_post_profile"]=> string(8) "everyone" ["allow_send_personal_conversation"]=> string(8) "everyone" ["allow_view_identities"]=> string(8) "everyone" ["allow_receive_news_feed"]=> string(8) "everyone" }
我的问题:
假设我想从数组
中获取'用户名'["username"]=> string(4) "Jony"
我该怎么办?我从未在PHP中使用过数组,我很新。
非常感谢!
答案 0 :(得分:0)
Arrays是PHP中的一个基本概念,所以如果你马上学习它们会很好。
$username = $userinfo['username'];
echo $username;