FreiChat related discussions
Login & Username integration Not Working

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 smooth
Can 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.

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

You have to supply userid and not the username ($_SESSION['username']) .

If you want users to be loaded from two different tables , then you will have to edit the query directly in freichat/server/drivers/base.php

$query = "SELECT DISTINCT " . $this->row_username . "," . $this->row_userid . "
FROM " . DBprefix . $this->usertable . "
WHERE " . $this->row_userid . "=?
LIMIT 1";



In the above query '?' refers to the supplied $ses, as of now you are passing $_SESSION['username'] . Modify the query accordingly .

You have to supply userid and not the username ($_SESSION[&#039;username&#039;]) . If you want users to be loaded from two different tables , then you will have to edit the query directly in freichat/server/drivers/base.php &amp;lt;code&amp;gt; $query = &quot;SELECT DISTINCT &quot; . $this-&amp;gt;row_username . &quot;,&quot; . $this-&amp;gt;row_userid . &quot; FROM &quot; . DBprefix . $this-&amp;gt;usertable . &quot; WHERE &quot; . $this-&amp;gt;row_userid . &quot;=? LIMIT 1&quot;; &amp;lt;/code&amp;gt; In the above query &#039;?&#039; refers to the supplied $ses, as of now you are passing $_SESSION[&#039;username&#039;] . Modify the query accordingly .
Necessity is the mother of all inventions!

i create a session with my user id and den add it 2 freichat i even change d setings and made freichat to use username as u taught me. It did nt work i don't undastand how to use two tables from my database.

i create a session with my user id and den add it 2 freichat i even change d setings and made freichat to use username as u taught me. It did nt work i don&#039;t undastand how to use two tables from my database.

Lets check whether the table names are correct , run below query in phpmyadmin(or equivalent)

SELECT DISTINCT username,id
FROM users
WHERE id!=0


If above query returns all users then your table set up is correct .

Lets check whether the table names are correct , run below query in phpmyadmin(or equivalent) &amp;lt;code&amp;gt; SELECT DISTINCT username,id FROM users WHERE id!=0 &amp;lt;/code&amp;gt; If above query returns all users then your table set up is correct .
Necessity is the mother of all inventions!
306
3
0
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft