phpBB3 login intergration problem. PHP/SQL
hejsaJeg har ospat en video chat og er ved at lave login intergration til mit phpBB3 forum, men det virker ikke helt efter planen.
Jeg bruger nogle handlers som er leveret af video chat producenten og som skulle være pre opsat til at bruge phpBB login system (database)
Mit problem er at den altid giver samme result ved nomal bruger login, Guest login virker ok (dvs. den kan se om bruger er oprettet, og siger at brugernavnet ikke kan bruges, såfremt dette allerede bruges)
Jeg vil være meget taknemlig hvis der var en som kunne tage et kig på mine handlers, da jeg ikke selv er super PHP/sql haj, jeg kunne eks godt tænke mig, hvis jeg kunne se hvor i scriptet det går galt, men den giver altid samme output. (jeg ville gerne have sql errors som output eks)
Håber virkelig nogen kan hjælpe.
Hvis der er brug for yderligere forklaring kan jeg også træffes på MSN/Skype
MSN : politi_20@hotmail.com
skype : Rene_iversen
Med venlig hilsen
René Iversen
Her er mine handler filer.
-------------------------------------
Guest Handler
-------------------------------------
<?php
require_once 'common.handler.php';
$userName = $_REQUEST['userName'];
$gender = $_REQUEST['gender'];
header('Content-type: text/xml');
$authAnswer = authChat("", "", "", $_REQUEST['userName']);
if ($authAnswer==0)
{
$userName = $_REQUEST['userName'];
$gender = $_REQUEST['gender'];
$userId = md5($userName.time());
$photo = FLASHCOMS_HTTP_ROOT."/photos/no_photo_big.png";
echo('
<login result="OK">
<userData>
<id>'.$userId.'</id>
<name>'.$userName.'</name>
<gender>'.$gender.'</gender>
<location>unknown</location>
<age>unknown</age>
<photo>'.$photo.'</photo>
<thumbnail>'.$photo.'</thumbnail>
<details/>
<level>guest</level>
</userData>
</login>
');
}
else echo('<login result="ERROR" msg="This username is taken. Please choose another one."/>');
?>
-------------------------------------
Login Handler
-------------------------------------
<?php
require_once "common.handler.php";
header('Content-type: text/xml');
$authAnswer = authChat("", $_REQUEST['login'], $_REQUEST['password']);
if ($authAnswer!=0)
{
xmlChat($authAnswer, 1, 1);
}
else echo('<login result="FAIL" error="error_authentication_failed"/>');
?>
-------------------------------------
Comon Handler
-------------------------------------
<?
/**
* phpBB3
**/
chdir('../../phpBB3/');
//phpBB includes
define('IN_PHPBB', true);
// Specify the path to you phpBB3 installation directory.
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
// The common.php file is required.
include($phpbb_root_path . 'common.' . $phpEx);
// since we are grabbing the user avatar, the function is inside the functions_display.php file since RC7
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
require_once $_SERVER['DOCUMENT_ROOT']."/chat7/config.php";
//Connect();
//include settings
//require_once "/chat/config.php";
//
mysql_query("SET NAMES 'utf8'");
$answer = '<invalid_params />';
function sqlQuery($queryType="", $action="", $id="", $login="", $password="")
{
if ($queryType=='AUTHORIZATION')
{
//SQL for Authorization
$sqlAuthorization = "
SELECT
user.user_id as id,
user.username as login,
user.user_password as password
FROM
phpbb_users AS user
WHERE ";
switch ($action)
{
case "AUTOLOGIN" : $sqlWhereAuthorization = "user.user_id = '".$id."'"; break;
case "LOGIN" : $sqlWhereAuthorization = "user.username = '".$login."'"; break;
case "GUEST" : $sqlWhereAuthorization = "user.username = '".$login."'"; break;
}
$returnSql = $sqlAuthorization.$sqlWhereAuthorization;
}
else if ($queryType=='PROFILE')
{
//SQL for Profile
$sqlProfile = "
SELECT
user.user_id as id,
user.username as login,
user.user_from,
user.user_occ as description,
user.user_avatar as photo,
user.user_avatar_type,
user.age,
user.sex as gender,
user.group_id as user_level
FROM
phpbb_users AS user
WHERE ";
$sqlWhereProfile = "user.user_id = '".$id."'";
$returnSql = $sqlProfile.$sqlWhereProfile;
}
else if ($queryType=='FRIENDS')
{
//SQL for Select Blocks
$sqlFriends = "
SELECT
friends.user_id as user_id,
friends.zebra_id as friend_id
FROM
phpbb_zebra AS friends
WHERE
friends.user_id = '".$id."' AND friend = 1";
$returnSql = $sqlFriends;
}
else if ($queryType=='BLOCKS')
{
//SQL for Select Blocks
$sqlBlocks = "
SELECT
blocks.user_id as user_id,
blocks.zebra_id as block_id
FROM
phpbb_zebra AS blocks
WHERE
blocks.user_id = '".$id."' AND foe = 1";
$returnSql = $sqlBlocks;
}
return $returnSql;
}
function authChat($uid="", $login="", $password="", $userName="")
{
global $auth;
if ($uid)
$query = sqlQuery('AUTHORIZATION', 'AUTOLOGIN', $uid);
else if ($login && $password)
{
$pass = $auth->login($login, $password);
if ($pass["error_msg"] != "LOGIN_ERROR_PASSWORD")
{
$query = sqlQuery('AUTHORIZATION', 'LOGIN', '', $login, $password);
}
}
else if ($userName)
$query = sqlQuery('AUTHORIZATION', 'GUEST', '', $userName);
$Authorization = @mysql_fetch_assoc(@mysql_query($query));
//var_dump($Authorization["id"]);
if ($Authorization["id"])
return $Authorization["id"];
else return 0;
}
function commonData($uid)
{
if ($uid)
{
$query = sqlQuery('PROFILE', '', $uid);
}
$UserProfile = @mysql_fetch_assoc(@mysql_query($query));
if ($UserProfile["id"])
{
//GET NAME
$name = $UserProfile["login"];
//GET GENDER
switch ($UserProfile["gender"])
{
case "1" : $gender = 'Male'; break;
case "0" : $gender = 'Female'; break;
default : $gender = "-";
}
//GET BIRTHDAY
$age = ($UserProfile["age"]!="") ? $UserProfile["age"] : "-";
//GET PHOTO
if ($UserProfile["user_avatar_type"]!=2)
{
//$AvatarPath = @mysql_fetch_assoc(mysql_query("SELECT * FROM phpbb_config WHERE config_name = 'avatar_path'"));
if ($UserProfile["photo"] != '')
{
$photo = SITE."download/file.php?avatar=".$UserProfile["photo"];
}
else $photo = FLASHCOMS."photos/no_photo_big.png";
}
else $photo = $UserProfile["photo"];
//GET LOCATION
if ($UserProfile["county_name"])
{
$location = $UserProfile["county_name"];
}else $location = "-";
if ($UserProfile["city_name"])
{
$city = $UserProfile["city_name"];
}
if ($country && $city) $symbol = ", ";
$location = $city.$symbol.$country;
//GET DESCRIPTION
if ($UserProfile["description"] != '' && $UserProfile["description"] != 'NULL')
{
$description = $UserProfile["description"];
}
//GET LEVEL
switch ($UserProfile["level"])
{
case "0" : $level = 'regular'; break;
case "1" : $level = 'regular'; break;
case "2" : $level = 'regular'; break;
case "3" : $level = 'regular'; break;
default : $level = 'regular';
}
//GET USER TYPE ADMIN OR MODERATOR
if ($UserProfile['user_level']=="5")
{
$typeUser = '<isAdmin>true</isAdmin>';
}
/*
else if ($UserProfile['isadmin']=="Moderator")
{
$typeUser = '<isModerator>true</isModerator>';
}
*/
else $typeUser = '';
//GET PROFILE
$profile = SITE."memberlist.php?mode=viewprofile&u=".$UserProfile["id"];
$UserData = array();
$UserData ["id"] = $UserProfile["id"];
$UserData ["username"] = $name;
$UserData ["gender"] = $gender;
$UserData ["age"] = $age;
$UserData ["photo"] = $photo;
$UserData ["location"] = ($UserProfile["user_from"]!="") ? $UserProfile["user_from"] : "-";
$UserData ["description"] = $description;
$UserData ["isAdminORModerator"] = $typeUser;
$UserData ["profile"] = $profile;
$UserData ["level"] = $level;
}
return $UserData;
}
function xmlChat($uid, $friends = 0, $blocks = 0)
{
$UserInfo = array();
$UserInfo = commonData($uid);
$xmlFriend="";
$xmlBlock="";
if ($UserInfo["id"])
{
$answer='<login result="OK">';
//get User Data
$answer.= '
<userData>
<id>'.$UserInfo ["id"].'</id>
<name><![CDATA['.$UserInfo ["username"].']]></name>
<gender>'.$UserInfo["gender"].'</gender>
<location><![CDATA['.$UserInfo ["location"].']]></location>
<age>'.$UserInfo ["age"].'</age>
<photo><![CDATA['.$UserInfo ["photo"].']]></photo>
<thumbnail><![CDATA['.$UserInfo ["photo"].']]></thumbnail>
<details>'.$UserInfo ["description"].'</details>
'.$UserInfo ["isAdminORModerator"].'
<level>'.$UserInfo ["level"].'</level>
<profileUrl><![CDATA['.$UserInfo ["profile"].']]></profileUrl>
</userData>';
//end get User Data
//get Friends Data
$answer.= '
<friends>';
if ($friends != 0)
{
$query = sqlQuery('FRIENDS', '', $uid);
$resultFriends = @mysql_query($query);
$UserInfoFriends = array();
while ($DataFriends = @mysql_fetch_assoc($resultFriends))
{
$UserInfoFriends = commonData($DataFriends["friend_id"]);
$xmlFriend .= '
<friend>
<id>'.$UserInfoFriends ["id"].'</id>
<name><![CDATA['.$UserInfoFriends ["username"].']]></name>
<gender>'.$UserInfoFriends["gender"].'</gender>
<location><![CDATA['.$UserInfoFriends ["location"].']]></location>
<age>'.$UserInfoFriends ["age"].'</age>
<photo><![CDATA['.$UserInfoFriends ["photo"].']]></photo>
<thumbnail><![CDATA['.$UserInfoFriends ["photo"].']]></thumbnail>
<details>'.$UserInfoFriends ["description"].'</details>
<level>'.$UserInfoFriends ["level"].'</level>
<profileUrl><![CDATA['.$UserInfoFriends ["profile"].']]></profileUrl>
</friend>';
}
}
$answer.= '
'.$xmlFriend.'
</friends>';
//end get Friends Data
$answer.= '
<blocks>';
if ($blocks != 0)
{
$query = sqlQuery('BLOCKS', '', $uid);
$resultBlocks = @mysql_query($query);
$UserInfoBlocks = array();
while ($DataBlocks = @mysql_fetch_assoc($resultBlocks))
{
$UserInfoBlocks = commonData($DataBlocks ["block_id"]);
$xmlBlock .= '
<block>
<id>'.$UserInfoBlocks ["id"].'</id>
<name><![CDATA['.$UserInfoBlocks ["username"].']]></name>
<gender>'.$UserInfoBlocks["gender"].'</gender>
<location><![CDATA['.$UserInfoBlocks ["location"].']]></location>
<age>'.$UserInfoBlocks ["age"].'</age>
<photo><![CDATA['.$UserInfoBlocks ["photo"].']]></photo>
<thumbnail><![CDATA['.$UserInfoBlocks ["photo"].']]></thumbnail>
<details>'.$UserInfoBlocks ["description"].'</details>
<level>'.$UserInfoBlocks ["level"].'</level>
</block>';
}
}
$answer.= '
'.$xmlBlock.'
</blocks>
';
$answer.= '</login>';
} else $answer = '<login result="FAIL" error="error_authentication_failed"/>';
echo $answer;
}
//Other Function
function getAge($birthday, $typeDate="YMD")
{
if ($birthday && $birthday!="0000-00-00" && $birthday!="NULL")
{
switch ($typeDate)
{
case "YMD" : list($year,$month,$day) = explode("-",$birthday); break;
case "DMY" : list($day, $month, $year) = explode("-",$birthday); break;
case "MDY" : list($month, $day, $year) = explode("-",$birthday); break;
case "YDM" : list($year, $day, $month) = explode("-",$birthday); break;
default : list($year,$month,$day) = explode("-",$birthday);
}
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($month_diff < 0) $year_diff--;
elseif (($month_diff==0) && ($day_diff < 0)) $year_diff--;
$age = $year_diff;
} else $age = "-";
return $age;
}
//end Other Function
//FRIENDS
$action = isset($_GET['action']) ? $_GET['action'] : null;
$userId = isset($_GET['user_id']) ? intval($_GET['user_id']) : null;
$friendId = isset($_GET['friend_id']) ? intval($_GET['friend_id']) : null;
$blockId = isset($_GET['block_id']) ? intval($_GET['block_id']) : null;
switch ($action)
{
case 'addFriend':
AddFriend($userId, $friendId);
break;
case 'removeFriend':
RemoveFriend($userId, $friendId);
break;
case 'addBlock':
AddBlock($userId, $blockId);
break;
case 'removeBlock':
RemoveBlock($userId, $blockId);
break;
}
function AddFriend($userId, $friendId)
{
$existsFriendR = mysql_query("SELECT * FROM phpbb_zebra WHERE user_id=".$userId." AND zebra_id=".$friendId);
if (!mysql_num_rows($existsFriendR)>0)
{
$sql = "INSERT INTO phpbb_zebra (user_id, zebra_id, friend)
values('".$userId."','".$friendId."','1')";
mysql_query($sql) or die(mysql_error());
echo("Add Friend!");
}
else
{
$sql = "DELETE FROM phpbb_zebra WHERE user_id = '".$userId."' and zebra_id = '".$friendId."'";
mysql_query($sql) or die(mysql_error());
$sql = "INSERT INTO phpbb_zebra (user_id, zebra_id, friend)
values('".$userId."','".$friendId."','1')";
mysql_query($sql) or die(mysql_error());
echo("Add Friend!");
}
}
function RemoveFriend($userId, $friendId)
{
$sql = "DELETE FROM phpbb_zebra WHERE user_id = '".$userId."' and zebra_id = '".$friendId."'";
mysql_query($sql) or die(mysql_error());
echo("Remove Friend!");
}
function AddBlock($userId, $blockId)
{
$existsFriendR = mysql_query("SELECT * FROM phpbb_zebra WHERE user_id=".$userId." AND zebra_id=".$blockId);
if (!mysql_num_rows($existsFriendR)>0)
{
$sql = "INSERT INTO phpbb_zebra (user_id, zebra_id, foe)
values('".$userId."','".$blockId."','1')";
mysql_query($sql) or die(mysql_error());
echo("Block Friend!");
}
else
{
$sql = "DELETE FROM phpbb_zebra WHERE user_id = '".$userId."' and zebra_id = '".$blockId."'";
mysql_query($sql) or die(mysql_error());
$sql = "INSERT INTO phpbb_zebra (user_id, zebra_id, foe)
values('".$userId."','".$blockId."','1')";
mysql_query($sql) or die(mysql_error());
echo("Add Block!");
}
}
function RemoveBlock($userId, $blockId)
{
$sql = "DELETE FROM phpbb_zebra WHERE user_id = '".$userId."' and zebra_id = '".$blockId."'";
mysql_query($sql) or die(mysql_error());
echo("Remove Friend!");
}
/*
header('Content-type: text/xml');
$authAnswer = authChat($_REQUEST['uid'], $_REQUEST['login'], $_REQUEST['password'], $_REQUEST['userName']);
if ($authAnswer!=0)
{
xmlChat($authAnswer, 1, 1);
}
else echo('<login result="FAIL" error="error_authentication_failed"/>');
*/
-------------------------------------
config.php (fra videochat)
-------------------------------------
<?php
define('SITE', 'http://'.$_SERVER['HTTP_HOST'].'/phpBB3/');
define('FLASHCOMS', 'http://'.$_SERVER['HTTP_HOST'].'/chat7');
define('FLASHCOMS_HTTP_ROOT', 'http://'.$_SERVER['HTTP_HOST'].'/chat7');
define('DOCUMENT_ROOT', $_SERVER['DOCUMENT_ROOT'].'/');
define('PHOTO_PATH', 'http://'.$_SERVER['HTTP_HOST'].'/uploades/icons/');
define('NO_PHOTO', 'http://'.$_SERVER['HTTP_HOST'].'/chat7/photos/no_photo_big.png');
define('COMMON_HANLER', 'http://'.$_SERVER['HTTP_HOST'].'/chat7/handlers/common.handler.php');
define('PRELOADER_LOGO_URL', '');
define('PRELOADER_BG_COLOR', '');
define('BG_COLOR', '');
// DB connection
define("DB_HOST", "localhost");
define("DB_USER", "XRemovedX");
define("DB_PASSWORD", "XRemovedX");
define("DB_NAME", "XRemovedX");
define("DB_PREFIX", "chat7_");
//Connect();
function Connect()
{
if(!mysql_connect(DB_HOST, DB_USER, DB_PASSWORD))
{
return false;
}
if(!mysql_select_db(DB_NAME))
{
return false;
}
return true;
}
?>