ich möchte die Userinfos eines eingeloggten phpBB-Users auch außerhalb des Forums nutzen und es ermöglichen daß man sich auf jeder beliebigen Seite ein- und ausloggt.
Zur ersten Sache hab ich folgendes Script gefunden:
Code: Alles auswählen
define('IN_PHPBB', true);
$phpbb_root_path = '../community/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
if ( $userdata['session_logged_in'] ) {
// this will display if they are logged in
echo "You are logged in!";
foreach($userdata as $name=> $value) {
echo "$name => $value<br>";
}
}
else
{
// this will display if they are not logged in
echo "You are not logged in!";
}
Das dumme ist nur daß dadurch der Code für die zweite Sache, das ein- und ausloggen nicht mehr klappt:
Code: Alles auswählen
define('override_phpbb_root_path', '../community/');
@include(override_phpbb_root_path . 'index_login.php');
Code: Alles auswählen
#################################################################
## Mod Title: Index_Login_Mod
## Mod Version: 2.0.0 :: Saturday, April 20, 2002 02:30 EST
## Author: Mike Dawidowicz, php@elitemaps.com
## URL: http://www.elitemaps.com
## Description: Login from any php enabled page on site.
##
## Installation Level: easy
## Installation Time: 2 Minutes
## Files To Edit: index_login.php, index_login.tpl, index_logged_in.tpl
## Included Files: yourpage.php, index_login.php, index_login.tpl, index_logged_in.tpl
#################################################################
## Security Disclaimer: This MOD Cannot Be Posted To Or Added At Any Non-Official phpBB Sites
#################################################################
# Index-Page Login on your site
# Displays Unread Private Messages and Users Online
#
# usage:
# @include('index_login.php');
#
# by: php@elitemaps.com
# do not remove this header
# Provided AS-IS. Updated for phpBB2.0.0
#
# packing list:
#
# readme.txt - instructions
# index_login.php - this file, the main component
# index_login.tpl - template for person not logged in
# index_logged_in.tpl - template for person logged in
# yourpage.php - example page that utilizes this file
#
# Example usage for index_login.php, see readme.txt
#################################################################
/**** BEGIN CONFIG ****/
//the full url of your website with ending slash
$site_url = ('http://192.168.0.2/');
//type your subdirectory with ending slash
$phpBB_url = ($site_url.'melonic/community/');
//if your done with the database after this file, set true,
//if you still need $db for other hacks, set this false
$close_db = True;
// define('CHECK_USERGROUP', 2);
/* uncomment define('CHECK_USERGROUP', 2); & set to the usergroup you'd like to have the user a member of.
can be used for a 'password protected area' that only members of a specific usergroup are allowed in.
3 is the first created group only (4 is next..etc), 1 is only anon, 2 is only admin.
check database to be sure what group id you'll be checking against. */
/**** END CONFIG ****/
define( 'IN_PHPBB', True );
$phpbb_root_path = "./"; // <-- should not be changed
$redirect = ( $siteurl . $PHP_SELF ); //can manually edit if you want them to go somewhere else
if ( !empty( $QUERY_STRING ) )
{
$q_string = preg_replace("/(sid=)(\w{32})(&)|(sid=)(\w{32})/", "", $QUERY_STRING);
if ( substr($q_string, -1) == "&" )
{
$q_string = substr($q_string, 0, -1);
}
$redirect .= "?" . $q_string;
/* phpBB2 will append_sid and another ? when cookies are off. When user puts wrong pass, they'll come back to this page with their query i.e. yourpage.php?test=1?sid= which will mess up the test variable. and test = 1? instead of 1, it's in phpBB2 not this script. */
}
// if we're including this file from a file that's not in the root, let it define root path
if ( defined( 'override_phpbb_root_path' ) )// this is where we prevent from malicious users
{
$phpbb_root_path = override_phpbb_root_path;
}
if ( !isset( $phpEx ) )
{
include( $phpbb_root_path . 'extension.inc' );
}
if( !defined( "PHPBB_INSTALLED" ) )
{
@include($phpbb_root_path . 'common.'.$phpEx);
}
if( !defined( "PHPBB_INSTALLED" ) )
{
die("PhpBB not installed or config file error.");
}
if (!$userdata)
{
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
}
//
// BEGIN Login Parameters
//
if ( defined('CHECK_USERGROUP') )
{
if ( is_int( CHECK_USERGROUP ) )
{
$check_usergroup = false;
$sql = "SELECT * FROM ".USER_GROUP_TABLE." WHERE user_id = ".$userdata['user_id'];
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Couldn't obtain user group information.", "", __LINE__, __FILE__, $sql);
}
while( $row = $db->sql_fetchrow($result))
{
if ( ($row['group_id'] == CHECK_USERGROUP) && !$row['user_pending'] )
{
$check_usergroup = true;
break;
}
}
}
}
else
{
$check_usergroup = true;
}
if (($userdata['user_active'] == 1) && ($userdata['user_id'] != -1) && $userdata['session_logged_in'] && $check_usergroup )
{
define('logged_in', True);
}
//
// END Login Parameters
//
//
// Get total users online
//
$sql = "SELECT u.username, u.user_id, s.session_logged_in, s.session_ip FROM ".USERS_TABLE." u, ".SESSIONS_TABLE." s WHERE u.user_id = s.session_user_id AND ( s.session_time >= ".( time() - 300 ) . " OR u.user_session_time >= " . ( time() - 300 ) . " )";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Couldn't obtain user online information.", "", __LINE__, __FILE__, $sql);
}
/*
$sql = "SELECT s.session_ip FROM ".SESSIONS_TABLE." s WHERE ( s.session_time >= ".( time() - 300 )." ) ";
if(!$result = $db->sql_query($sql))
{
message_die(GENERAL_ERROR, "Couldn't obtain user/online information.", "", __LINE__, __FILE__, $sql);
}
while( $row = $db->sql_fetchrow($result) )
{
$users_online++;
}
*/
$users_online = 0;
$prev_user_id = "0";
$prev_session_ip = "0";
while( $row = $db->sql_fetchrow($result) )
{
if ( $row['session_logged_in'] )
{
// Skip multiple sessions for one user
if ( $prev_user_id != $row['user_id'] )
{
$users_online++;
}
$prev_user_id = $row['user_id'];
}
else
{
if ( $row['session_ip'] != $prev_session_ip)
{
$users_online++;
}
}
$prev_session_ip = $row['session_ip'];
}
if ( $users_online == 1 )
{
$txt_users_online = "$users_online user";
}
else
{
$txt_users_online = "$users_online users";
}
//
// Done Getting Total Users Online
//
if ( defined('logged_in') )
{
// they're logged in, welcome them, check to see if they're admin, grab their info
$template->set_filenames(array(
"body" => "index_logged_in.tpl")
);
if ( $userdata['user_rank'] == 1 ) {
$admin_msg = "<a href=\"" . append_sid( $phpBB_url . "admin/index." . $phpEx ) . "\">Admin</a>";
}
$template->assign_vars(array(
"PHPBB_URL" => $phpBB_url,
"USERNAME" => $userdata['username'],
"ADMIN" => $admin_msg,
"PHP_EXT" => $phpEx,
"PRIV_MSG_COUNT" => $userdata['user_new_privmsg'],
"USERS_ONLINE" => $txt_users_online,
"PRIV_MSG_LINK" => append_sid( $phpBB_url . "privmsg." . $phpEx ."?folder=inbox" ),
"FORUM_LINK" => append_sid( $phpBB_url . "index." . $phpEx ),
"LOGOUT_LINK" => $phpBB_url . "login." . $phpEx ."?logout=true",
"COPY" => "by: <a href=\"mailto:php@elitemaps.com\">AceMan</a>",
"USER_ID" => $userdata['user_id'],
"REDIRECT" => $redirect
)
);
$template->pparse("body");
}
else
{
// if they havnt logged in by the form, session, or cookie, send them the form
$template->set_filenames(array(
"body" => "index_login.tpl")
);
$template->assign_vars(array(
"PHPBB_URL" => $phpBB_url,
"REDIRECT" => $redirect,
"PHP_EXT" => $phpEx,
"USERS_ONLINE" => $txt_users_online,
"REGISTER_LINK" => append_sid( $phpBB_url . "profile." . $phpEx ."?mode=register" ),
"COPY" => "by: <a href=\"mailto:php@elitemaps.com\">AceMan</a>",
"FORGOT_PASS_LINK" => append_sid( $phpBB_url . "profile.php?mode=sendpassword" )
)
);
$template->pparse("body");
}
if ( isset($db) && $close_db ){
$db->sql_close();
}
Allgemeiner Fehler
Could not obtain user/online information
Woran kann das liegen?
Vielen Dank schonmal für die Antworten und sorry daß es soviel codegeschnipsel ist,
dantist