I have a site that uses login script and i use
$_SESSION["username"]
as my session and i did all the necessary changes with the page i want the chat to appear and i also change the hardcore and i can see my user in the admin end of the chat when click on moderation.but if a user logs in it still display as guest below is my script where the integration occours.
<?php $ses = null; // Return null if user is not logged in
if(isset($_SESSION['username']))
{
if($_SESSION['username'] != null) // Here null is guest
{
$ses=$_SESSION['username']; //LOOK, now username is suppose to pass to FreiChat but it won't.
}
}
if(!function_exists("FreiChatx_get_hash"))
{
function FreiChatx_get_hash($ses){//And the rest of the code as it is . .
if(is_file("C:/wamp/www/Dagogo_temp/freichat/hardcode.php")){
require "C:/wamp/www/Dagogo_temp/freichat/hardcode.php";
$temp_id = $ses . $uid;
return md5($temp_id);
}
else
{
echo "<script>alert('module freichatx says: hardcode.php file not
found!');";
}
return 0;
}
}
?>
<script type="text/javascript" language="javascipt" src="http://localhost/Dagogo_temp/freichat/client/main.php?id=<?php%20echo%20%24ses;?>&xhash=<?php%20echo%20freichatx_get_hash(%24ses);%20?>"></script><link rel="stylesheet" href="http://localhost/Dagogo_temp/freichat/client/jquery/freichat_themes/freichatcss.php" type="text/css"><!--===========================FreiChatX=======END=========================-->
and the hard core is below
<em>
<?php /* Data base details */
$con = 'mysql'; // MySQL , Oracle , SQLite , PostgreSQL
$username='root'; // Database username
$password=''; //Database password
$client_db_name='online'; //Database name
$host='localhost'; //host
$port=''; //optional port for some servers using different port
$driver='Custom'; //Integration driver
$db_prefix=''; //prefix used for tables in database
$uid='52b2c4244f15f'; //Any random unique number
$PATH = 'freichat/'; // Use this only if you have placed the freichat folder somewhere else
$installed=true; //make it false if you want to reinstall freichat
$admin_pswd='adminpass'; //backend password
$debug = false;
/* email plugin */
$smtp_username = '';
$smtp_password = '';
/* Custom driver */
$usertable='users'; //specifies the name of the table in which your user information is stored.
$row_username='username'; //specifies the name of the field in which the user's name/display name is stored.
$row_userid='id'; //specifies the name of the field in which the user's id is stored (usually id or userid)
$avatar_field_name = 'avatar';
</em></em>
<em>
<?php require 'base.php';
class Custom extends driver_base {
public function __construct($db) {
//parent::__construct();
$this->db = $db;
}
//------------------------------------------------------------------------------
public function getDBdata($session_id, $first) {
if ($session_id != null) {
$userID = strip_tags($session_id);
$_SESSION[$this->uid . 'is_guest'] = 0;
} else {
$_SESSION[$this->uid . 'is_guest'] = 1;
$_SESSION[$this->uid . 'usr_name'] = $_SESSION[$this->uid . 'gst_nam'];
$_SESSION[$this->uid . 'usr_ses_id'] = $_SESSION[$this->uid . 'gst_ses_id'];
}
if (($_SESSION[$this->uid . 'time'] online_time || isset($_SESSION[$this->uid . 'usr_name']) == false || $first == 'false') && $_SESSION[$this->uid . 'is_guest'] == 0) { //To consume less resources , now the query is made only once in 15 seconds
$query = "SELECT DISTINCT " . $this->row_username . "," . $this->row_userid . "
FROM " . DBprefix . $this->usertable . "
WHERE " . $this->row_userid . "=?
LIMIT 1";
$res_obj = $this->db->prepare($query);
$res_obj->execute( array($userID) );// var_dump($res_obj);
$res = $res_obj->fetchAll();
if ($res == null) {
$this->freichat_debug("Incorrect Query : " . $query . " \n session id: ". $session_id ."\n PDO error: ".print_r($this->db->errorInfo(),true));
$_SESSION[$this->uid . 'is_guest'] = 1;
$_SESSION[$this->uid . 'usr_name'] = $_SESSION[$this->uid . 'gst_nam'];
$_SESSION[$this->uid . 'usr_ses_id'] = $_SESSION[$this->uid . 'gst_ses_id'];
}
foreach ($res as $result) {
if (isset($result[$this->row_username])) { //To avoid undefined index error. Because empty results were shown sometimes
$_SESSION[$this->uid . 'usr_name'] = $result[$this->row_username];
$_SESSION[$this->uid . 'usr_ses_id'] = $result[$this->row_userid];
}
}
}
else {
$this->freichat_debug("Wrong method defined!");
}
}
//------------------------------------------------------------------------------
public function linkprofile_url($result, $r_path, $def_avatar) {
$iden = $result['profile_iden']; //additional data
$id = $result['session_id'];
$str = "<span id='freichat_profile_link_" . $id . "' class="freichat_linkprofile_s">";
$path = "<a href="%22%20.%20%24r_path%20.%20%22index.php?userid=%22%20.%20%24id%20.%20%22">";
$str = $str.$path."<img title='" . $this->frei_trans[' profilelink . class="freichat_linkprofile" src="%22%20.%20%24def_avatar%20.%20%22" alt="view"></a></span>";
//return $str;
return '';
}
//------------------------------------------------------------------------------
public function avatar_url($avatar) {
$murl = str_replace("server/freichat.php", "", $this->url);
$avatar_url = $murl . 'client/jquery/user.jpeg';
return $avatar_url;
}
//------------------------------------------------------------------------------
public function getList() {
$user_list = null;
if ($this->show_name == 'guest') {
$user_list = $this->get_guests();
} else if ($this->show_name == 'user') {
$user_list = $this->get_users();
} else {
$this->freichat_debug('USER parameters for show_name are wrong.');
}
return $user_list;
}
//------------------------------------------------------------------------------
public function get_guests() {
$query = "SELECT DISTINCT status_mesg,username,session_id,status,guest
FROM frei_session
WHERE time>" . $this->online_time2 . "
AND session_id!=" . $_SESSION[$this->uid . 'usr_ses_id'] . "
AND status!=2
AND status!=0";
//echo $query;
$list = $this->db->query($query)->fetchAll();
return $list;
}
//------------------------------------------------------------------------------
public function get_users() {
$query = "SELECT DISTINCT status_mesg,username,session_id,status,guest
FROM frei_session
WHERE time>" . $this->online_time2 . "
AND session_id!=" . $_SESSION[$this->uid . 'usr_ses_id'] . "
AND guest=0
AND status!=2
AND status!=0";
$list = $this->db->query($query)->fetchAll();
return $list;
}
//------------------------------------------------------------------------------
public function get_buddies() {
$query = "SELECT DISTINCT status_mesg,username,session_id,status,guest
FROM frei_session
WHERE time>" . $this->online_time2 . "
AND session_id!=" . $_SESSION[$this->uid . 'usr_ses_id'] . "
AND guest=0
AND status!=2
AND status!=0";
$list = $this->db->query($query)->fetchAll();
return $list;
}
//------------------------------------------------------------------------------
public function load_driver() {
define("DBprefix", $this->db_prefix);
$session_id = $this->options['id'];
$custom_mesg = $this->options['custom_mesg'];
$first = $this->options['first'];
// 1. Connect The DB
// DONE
// 2. Basic Build the blocks
$this->createFreiChatXsession();
// 3. Get Required Data from client DB
$this->getDBdata($session_id, $first);
$this->check_ban();
// 4. Insert user data in FreiChatX Table Or Recreate Him if necessary
$this->createFreiChatXdb();
// 5. Update user data in FreiChatX Table
$this->updateFreiChatXdb($first, $custom_mesg);
// 6. Delete user data in FreiChatX Table
$this->deleteFreiChatXdb();
// 7. Get Appropriate UserData from FreiChatX Table
if ($this->usr_list_wanted == true) {
$result = $this->getList();
return $result;
}
// 8. Send The final Data back
return true;
}
}
</em>
Please check it out and assist me please.
I love the freichat it
smoothCan i add two tables to $row_username='username';
because i have two different tables with with users in them and i want them all to chat.
Thanks in advance.