• 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

Join Channel using redirect page and $_SESSION

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

Post a reply
22 posts • Page 1 of 2 • 1, 2

Postby Andaho » Sun Dec 19, 2010 4:03 pm

I have spent a couple hours reading through the forum, and know that "It is recommended that you use $_SESSION, by setting whatever get/post values you will need into the session on a page BEFORE the chat page, then redirect to the chat page"...

I have never used PHP before, and I have also spent a couple hours googling about $_SESSION and how to use it... but I am still none the wiser...

Can someone supply an example of an html redirecting page to be able to use the url chat.php?channel=exampleroom to join chat rooms?

I'm sure for someone that knows PHP it's a 2 minute job... but to a PHP newbie I still have no progress after 2 hours...
Andaho
Member
 
Posts: 14
Joined: Tue Dec 14, 2010 9:43 pm
Top

Postby re*s.t.a.r.s.*2 » Sun Dec 19, 2010 7:09 pm

Code: Select all
<?php

$UserNick=$_SESSION['your session name here'];
if(isset($UserNick))
{
echo "<p>Your session is set in previous page</p>";
}else{
echo "<p>Session is not set, so please redirect me to the login form or page where it can be set</p>";
header('location:url-where-you-can-set-sessions'); // this will get you where you can set it up.
}

?>

There goes, it will get you started..
Free Singles Chat Rooms No Registration Required
Text and Chat Singles no need to register or app required
Sala De Bate Papo Online Grátis E Sem Cadastro
re*s.t.a.r.s.*2
Support Team
 
Posts: 612
Joined: Wed Sep 24, 2008 4:04 pm
Location: los angeles CA
  • Website
Top

Postby Andaho » Sun Dec 19, 2010 7:42 pm

Umm... thanks for the quick reply Yoda :)

it's not a usernick that I want to get though...

my chat is here: http://die2nite.net/chat/index.php

I want to create a redirecting page that will allow a channel name e.g. http://die2nite.net/chat/chat.php?room=exampleroom1 which will then grab the "exampleroom1" from the url, and add it as session data, and forward to http://die2nite.net/chat/index.php to then recall the "exampleroom1" as the channel to join...

so I need something like this:

Code: Select all
<?php
session_start();
$_SESSION['channel']=$_GET["room"];
?>

is that right?
Last edited by Andaho on Sun Dec 19, 2010 7:42 pm, edited 1 time in total.
Andaho
Member
 
Posts: 14
Joined: Tue Dec 14, 2010 9:43 pm
Top

Postby re*s.t.a.r.s.*2 » Sun Dec 19, 2010 8:12 pm

I would use $_POST[]; instead never played with GET thought, try it nothing to loss..

set it in login form have a option to "channels" that choose the available rooms make the form to look for itself <?php $PHP_SELF; ?> , set the session with the $_POST and if set redirect to the chat, chat will pick up the session and then give you the channel..

Do you get what I am saying?
Free Singles Chat Rooms No Registration Required
Text and Chat Singles no need to register or app required
Sala De Bate Papo Online Grátis E Sem Cadastro
re*s.t.a.r.s.*2
Support Team
 
Posts: 612
Joined: Wed Sep 24, 2008 4:04 pm
Location: los angeles CA
  • Website
Top

Postby Andaho » Sun Dec 19, 2010 9:23 pm

re*s.t.a.r.s.*2 wrote:Do you get what I am saying?

I still don't think that's what I'm trying to achieve... I don't even know how the $_GET works or what $_POST does...

I'm googling around trying to find an example script, but not having much luck :( seems like such a simple thing, but it's only simple if you know how.

Thanks for trying to help Yoda, but I really want to be able to use the url to define the channel.
Andaho
Member
 
Posts: 14
Joined: Tue Dec 14, 2010 9:43 pm
Top

Postby OldWolf » Tue Dec 21, 2010 1:27 am

This will explain get/post:
http://www.tizag.com/phpT/postget.php

This will explain sessions:
http://www.tizag.com/phpT/phpsessions.php

This site is a very good one, if you need more background info, I suggest going through more of their tutorials.

Also, just fyi, I googled get post tutorial and session tutorial to find those both, they are the top result. Tizag is a great site though, but there are more options if that doesn't work.
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 Andaho » Fri Dec 24, 2010 8:59 pm

Thanks for your help, but I still think I must be doing something wrong because it doesn't work

This is my join.php page:

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=http://www.die2nite.net/chat">
</head>

And I use this URL as an example test: http://www.die2nite.net/chat/join.php?c ... estChannel

My index.php looks like this:

Code: Select all
<?php

date_default_timezone_set('Europe/Paris');
require_once dirname(__FILE__)."/src/phpfreechat.class.php";
$params = array();
$params["title"] = "Die2Nite.net Instant Chat";
$params['admins'] = array('Andaho'  => 'Andaho', 'Jacob' => 'Jacob');
$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
$params["debug"] = false;
$params["theme"] = "die2nite";
$params["nickname_colorlist"] = array('#3399ff','#9999ff','#66ccff','#33ff33','#669966','#ffff00','#ff9900','#ff6666','#ff3300','#cc33cc','#000000','#cc9966','#999999');
$params["channels"] = array("Die2Nite.net Lobby", $_SESSION['url']);
$params["max_nick_len"] = 20;
$params["timeout"] = 60000;
$params['skip_proxies'] = array('censor');
$params["time_format"] = "H:i";
$params["bbcode_colorlist"] = array('#FFFFFF','#3399ff','#9999ff','#66ccff','#33ff33','#669966','#ffff00','#ff9900','#ff6666','#ff3300','#cc33cc','#999999','#000000');

$chat = new phpFreeChat( $params );

?>

But it doesn't work... It only joins the single channel "Die2Nite.net Lobby"... What am I doing wrong?
Last edited by Andaho on Fri Dec 24, 2010 9:05 pm, edited 1 time in total.
Andaho
Member
 
Posts: 14
Joined: Tue Dec 14, 2010 9:43 pm
Top

Postby re*s.t.a.r.s.*2 » Fri Dec 24, 2010 10:18 pm

Check if the session is set:

Code: Select all
<?php
session_start();
$_SESSION['url'] = $_GET["channel"]; // retrive ?channel= and store in url variable
$channel=$_SESSION['url'];
if((isset($channel)) AND (!empty($channel))){
echo '<head>
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.die2nite.net/chat">
</head>';
}
?>

this will only redirect you if the session has something and is not empty..
Last edited by re*s.t.a.r.s.*2 on Fri Dec 24, 2010 10:54 pm, edited 1 time in total.
Free Singles Chat Rooms No Registration Required
Text and Chat Singles no need to register or app required
Sala De Bate Papo Online Grátis E Sem Cadastro
re*s.t.a.r.s.*2
Support Team
 
Posts: 612
Joined: Wed Sep 24, 2008 4:04 pm
Location: los angeles CA
  • Website
Top

Postby Andaho » Fri Dec 24, 2010 11:12 pm

thanks for the reply utan, but I have verified that the session is being created by deleting the redirecting line, and it posts the variable on the page... I appreciate you trying to help utan, but can anyone else that knows php help?
Andaho
Member
 
Posts: 14
Joined: Tue Dec 14, 2010 9:43 pm
Top

Postby re*s.t.a.r.s.*2 » Sat Dec 25, 2010 12:01 am

If is set then is phpfreechat that is not picking the session up,

there is the problem, not your script or mine..
Free Singles Chat Rooms No Registration Required
Text and Chat Singles no need to register or app required
Sala De Bate Papo Online Grátis E Sem Cadastro
re*s.t.a.r.s.*2
Support Team
 
Posts: 612
Joined: Wed Sep 24, 2008 4:04 pm
Location: los angeles CA
  • Website
Top

Postby re*s.t.a.r.s.*2 » Sat Dec 25, 2010 4:03 am

Well,
I was testing in my locahost, and it seems that PFC lose the content of the variable when you get to the $params['channels'], although the content has been set with the Get super global...
Tried to print out the content outside in the HTML and I could print out the content fine, PFC get you an error with parameter lose /join {channel} or something like it..

I have manage to get it to work using GET and regular cookies same test as your resulted in the param channels set sussesfully but error out if I tried sessions..

Thats something I cant understand why PFC channels array fails to pic the content if you used Sessions and GET super global but works fine if used Cookies...


Let me know if you are interested in the cookie code..
Also read the faq http://www.phpfreechat.net/faq

branches before PFC 1 worked with GET fine... regards
Last edited by re*s.t.a.r.s.*2 on Sat Dec 25, 2010 4:05 am, edited 1 time in total.
Free Singles Chat Rooms No Registration Required
Text and Chat Singles no need to register or app required
Sala De Bate Papo Online Grátis E Sem Cadastro
re*s.t.a.r.s.*2
Support Team
 
Posts: 612
Joined: Wed Sep 24, 2008 4:04 pm
Location: los angeles CA
  • Website
Top

Postby Andaho » Sun Dec 26, 2010 12:00 am

All I want to achieve is custom made channels joining with a url "join.php?channel=anychannelname"... if this can be done with cookies or any other method, I would be very grateful of the help :)
Andaho
Member
 
Posts: 14
Joined: Tue Dec 14, 2010 9:43 pm
Top

Postby re*s.t.a.r.s.*2 » Sun Dec 26, 2010 12:25 am

Yes it can be done with cookies but since regular cookies requires a time to expire and will not expire if you close the browser like sessions cookies, I dont think it will be of any help for you because you want that the channed gets deleted when the user close his her browser...
Free Singles Chat Rooms No Registration Required
Text and Chat Singles no need to register or app required
Sala De Bate Papo Online Grátis E Sem Cadastro
re*s.t.a.r.s.*2
Support Team
 
Posts: 612
Joined: Wed Sep 24, 2008 4:04 pm
Location: los angeles CA
  • Website
Top

Postby Andaho » Sun Dec 26, 2010 12:42 am

Well... I think I explained the purpose for my chat before, but no harm in repeating... the browser game www.die2nite.com is a game of short survival towns that last around ~10 days depending on how good the players are... the towns have random names... I want to have multiple channels for the towns.

The game itself has an in-game town forum, and I want to post a url in the town forum like this for example: http://die2nite.net/chat/join.php?channel=townname

Could cookies achieve this? - would I still need a redirecting page? - could the cookie be programmed to take the variable from the URL and overwrite any existing variable?
Andaho
Member
 
Posts: 14
Joined: Tue Dec 14, 2010 9:43 pm
Top

Postby re*s.t.a.r.s.*2 » Sun Dec 26, 2010 12:54 am

Using cookies you can even set in the same chat index.php, I did it and it works... if you wanna learn about go here http://php.net/manual/en/function.setcookie.php

regards..
Free Singles Chat Rooms No Registration Required
Text and Chat Singles no need to register or app required
Sala De Bate Papo Online Grátis E Sem Cadastro
re*s.t.a.r.s.*2
Support Team
 
Posts: 612
Joined: Wed Sep 24, 2008 4:04 pm
Location: los angeles CA
  • Website
Top

Next

Post a reply
22 posts • Page 1 of 2 • 1, 2

Return to General Support (v1.x)

Who is online

Users browsing this forum: No registered users and 7 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