• 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

How to default the channel when user hits a page?

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

Post a reply
5 posts • Page 1 of 1

Postby homerlex » Wed Jan 12, 2011 5:57 pm

I'm new to this and playing around with 1.3. I want to have a page that forces the user into a specified channel.

I thought perhaps something like this would work:
$params["channels"] = array($_GET["channel"]);

The problem is that it always defaults the user to the first channel created. For example:

- User 1 hits chat.php?channel=room_1. He is properly put in room_1.
- User 2 hits chat.php?channel=room_2. He is also put in room_1. Is there a way to just get him to automatically be put into whatever name is specified on the channel param?

Thanks!
homerlex
New member
 
Posts: 3
Joined: Wed Jan 12, 2011 5:43 pm
Top

Postby Andaho » Thu Jan 13, 2011 9:55 am

Please see this thread: http://www.phpfreechat.net/forum/viewtopic.php?id=4715
Andaho
Member
 
Posts: 14
Joined: Tue Dec 14, 2010 9:43 pm
Top

Postby homerlex » Thu Jan 13, 2011 2:45 pm

Andaho wrote:Please see this thread: http://www.phpfreechat.net/forum/viewtopic.php?id=4715

OK - I went though the thread an though I followed it properly. I set up a test (see code below) and it seems to redirect the the specified channel on the user's first hit. However, if that same user tries to hit the join page with a different channel name he is still joined into the first channel.

Example:

User first hits /join?channel=first_channel. He is redirected to chat and is joined into first_channel. Then, the same user hits /join?channel=second_channel. He is redirected and again is put into first_channel.

I'd like to be able to put users into different channels based on where they are on the site.

What am I doing wrong?

join.php:
Code: Select all
<?php
session_start();
$_SESSION['url'] = $_GET["channel"]; // retrive ?channel= and store in url variable
echo "Connecting to channel: ". $_SESSION['url']. " . . ."; // display session variable
?>
<head>
<meta HTTP-EQUIV="REFRESH" content="0; url=/chat.php">
</head>

chat.php:
Code: Select all
<?php
session_start();
require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["title"] = "My chat";
$params["nick"] = "guest".rand(1,1000);  // setup the intitial nickname
$params['firstisadmin'] = true;
$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
$params["debug"] = false;
$params["channels"] = array($_SESSION['url']);

$chat = new phpFreeChat( $params );

?>
homerlex
New member
 
Posts: 3
Joined: Wed Jan 12, 2011 5:43 pm
Top

Postby homerlex » Thu Jan 13, 2011 4:46 pm

I found that resetting the session each time solves the problem.

New join code:

Code: Select all
session_restart();
$_SESSION['channel'] = $_GET["channel"];

.
.
.

function session_restart()
{
    if (session_name()=='') {
        session_start();
    }
    else {
        session_destroy();
        session_start();
        session_regenerate_id();
    }
}

The problem with the above solution is that I am also controlling the nickname. The same redirect solution works OK with the nickname on the url until I hit the join url again (to change rooms) with the same nickname on the url.

When I do this I get the popup that says "Nickname is already in use"

Is there any way to disable this check (since I will be controlling the names used anyway)?

Just a note: we'll eventually have a more secure mechanism to control the nickname so no one can just manually pass in whatever they want :-).
Last edited by homerlex on Thu Jan 13, 2011 4:49 pm, edited 1 time in total.
homerlex
New member
 
Posts: 3
Joined: Wed Jan 12, 2011 5:43 pm
Top

Postby OldWolf » Fri Jan 14, 2011 4:35 am

I think the system actually uses nick as the identifier for messages and what have you (there may be an id as well, but I think it's just nick), so in short, no, you couldn't disable it without creating a potential for huge problems.

However, I'm not certain of this. Other users are welcome to chime in with a more certain answer.
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


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 21 guests

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