• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ General Support (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

Unable to change username once someone is connected

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
5 posts • Page 1 of 1

Postby moxdiamond » Wed Jan 28, 2009 1:06 am

I have almost configured the chat program but am stuck on one more thing. When someone first loads the page they are assigned a random username (guest####). The site has it's own user management program. I would like it to use the persons account username whenever a user is logged in and only use the guest access when they are not.

If someone logs in before visiting the chat page their username is used just as I want it to be. But when someone visits that chat room while not logged in ... they get assigned a random username (as expected) but if the person then logs in after that point the chat program still continues to use the random username. It is as if the program has cached the username and will continue to use it until the cache is cleared or a substantial time passes.

The username is passed via the custom parameters: the text of which follows:

Code: Select all
<?PHP

  $params2 = array();
  $params2["title"] = "ChatAway";
  $params2["nick"] = "guest".rand(1,10000);  // setup the intitial nickname
  if(isset($_SESSION['the_account']['username']) && $_SESSION['the_account']['username'] != '') { $params2["nick"] = $_SESSION['the_account']['username']; }
  $params2['frozen_nick'] = true;
  $params2["isadmin"] = false; // do not use it on production servers ;)
  $params2['height'] = '350px';
  $params2['clock'] = false;
 $params2["serverid"] = md5('fsdkljfsdfsdsdf'); // calculate a unique id for this chat

  $chat = new phpFreeChat($params2);
  $chat->printChat();

?>

If I rehash the chat window the program will forget about the previous guest username and take the logged in one.

Any way to work around this caching behavior so as to allow for usernames to be changeable after the fact? I don't want people to be able to define their own nicknames so that no one is able to pretend to be someone they are not, which is why I have frozen_nick set.

Thanks in advance.
Last edited by moxdiamond on Wed Jan 28, 2009 1:07 am, edited 1 time in total.
moxdiamond
New member
 
Posts: 5
Joined: Mon Jan 05, 2009 8:02 pm
Top

Postby OldWolf » Wed Jan 28, 2009 2:07 am

You're right, it is holding their name. However, if frozen nick is set to true always, that should make it stick to the name currently assigned. I'm not sure why that's not working actually.
Signature:
Read before Posting: Forum Rules
Note: I am unable to offer support through PM/e-mail at this time.
OldWolf
Site Admin
 
Posts: 1918
Joined: Sun Sep 23, 2007 5:48 am
Top

Postby phpfreechat » Wed Jan 28, 2009 3:53 pm

I think it will work once you will declare frozen_nick as a "dynamic parameter" (not cached). Try to add this:
$params2['dyn_params'] = array('frozen_nick');
phpfreechat
Site Admin
 
Posts: 2657
Joined: Tue Feb 07, 2006 3:35 pm
Location: France
Top

Postby buo » Thu Sep 10, 2009 8:15 am

1.anyone who is able to explain the code below,
2.About moxdiamond, how about having a logout button, which destroys session session_name( "phpfreechat" );? will it work even if i dont clear the cache?

function pfcUserConfig()
{
$c =& pfcGlobalConfig::Instance();

// start the session : session is used for locking purpose and cache purpose
session_name( "phpfreechat" );
if(session_id() == "") session_start();

// the nickid is a public identifier shared between all the chatters
// this is why the session_id must not be assigned directly to the nickid
$this->nickid = sha1(session_id());

// user parameters are cached in sessions
$this->_getParam("nick");
if (!isset($this->nick)) $this->_setParam("nick",""); // setup a blank nick if it is not yet in session
$this->_getParam("active");
if (!isset($this->active)) $this->_setParam("active",false);
$this->_getParam("channels");
if (!isset($this->channels)) $this->_setParam("channels",array());
$this->_getParam("privmsg");
if (!isset($this->privmsg)) $this->_setParam("privmsg",array());
$this->_getParam("serverid");
if (!isset($this->privmsg)) $this->_setParam("serverid",$c->serverid);
}
buo
New member
 
Posts: 6
Joined: Wed Sep 09, 2009 6:13 am
Top

Postby buo » Thu Sep 10, 2009 9:06 am

try this one, it worked for me:

you must have two pages
chat_form.php - where the user could enter their username and select a room
chatroom.php - where the chatroom is located, nick and channel came from chat_form.php



1. code for chat_form.php

$showLoginForm = 'Y';

if($_POST['submit'])
{
$showLoginForm = 'N';
$username = isset($_POST['username'])? $_POST['username']:'';
$room = isset($_POST['room'])?$_POST['room']:'';

if($username == '')
{
$msg = 'Please enter a user name<br>';
$showLoginForm = 'Y';
}
if($room == '')
{
$msg .= 'Please select a room';
$showLoginForm = 'Y';
}

if($showLoginForm == 'N')
{
header('location:chatroom.php?username=' . $username . '&room=' . $room);
}
}



if($showLoginForm == 'Y')
{
?>
<form method="post" action="chat_form.php">
<h3>Enter Chatroom</h3>
<span style="color:red"><?php echo $msg;?></span>
<table>
<tr><td>Name:</td><td><input type="text" name="username"/></td></tr>
<tr><td>Room:</td><td><select name="room">
<option value="clients">Clients</option>
<option value="Customer Support">Customer Support</option>
<option value="Web Administrators">Web Administrators</option>
</select>
</td></tr>
<tr><td></td><td><input type="submit" value=" Join " name="submit" /></td></tr>
</table>
</div>
</form>
<?php } ?>


2. code for chatroom.php


if($_POST['logout']){
session_name( "phpfreechat" );
session_start();

$_SESSION = array();

if (isset($_COOKIE[session_name()])) {
setcookie(session_name(), '', time()-42000, '/');
}

session_destroy();
header('location:chat_form.php');

}


require_once "phpfreechat.class.php";

$params['dyn_params'] = array('nick','channels');
$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
$params["title"] = "Chat Rooms";
$params["nick"] = $_GET['username']; // setup the intitial nickname
$params["channels"] = array($_GET['room']);
$params["height"] = "200";
$params["max_msg"] = 0;
$params["isadmin"] = true;
$chat = new phpFreeChat( $params );


<form action="chatroom.php" method="post">
<input type="submit" name="logout" value="Logout" />
</form>

<?php $chat->printChat(); ?>



hope this helps
buo
New member
 
Posts: 6
Joined: Wed Sep 09, 2009 6:13 am
Top


Post a reply
5 posts • Page 1 of 1

Return to General Support (v1.x)

Who is online

Users browsing this forum: No registered users and 27 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
cron
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub