• 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

Weird session bug?

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

Post a reply
8 posts • Page 1 of 1

Postby jasonc » Wed Apr 04, 2012 5:16 pm

I'm integrating the chat into an existing website, and I have a weird issue.

WAMP server, php 5.3.4, Apache 2.2.17, windows server 2003. the chat works great, in the demo and standalone scripts ive tested it with. However, when integrating it via an include file, I'm having a problem setting the nick parameter.

This doesn't work, it just sits at the loading div:

$unamearry = explode(" ",$_SESSION["displayname"]);
$firstname = $unamearry[0];
$params["nick"] = iconv("ISO-8859-1", "UTF-8", $firstname);

However, if i call session_start() again, even though it has already been started and errors out, everything works great. So, if i disable the error showing, it all technically works:

ini_set("display_errors",'off');
session_start();
ini_set("display_errors",'on');
$unamearry = explode(" ",$_SESSION["displayname"]);
$firstname = $unamearry[0];
$params["nick"] = iconv("ISO-8859-1", "UTF-8", $firstname);

The question is Why?
jasonc
New member
 
Posts: 4
Joined: Wed Apr 04, 2012 5:03 pm
Top

Postby re*s.t.a.r.s.*2 » Wed Apr 04, 2012 6:01 pm

Hi,

Where in your index you already started the session? (We need to see the index.php code)

You need to start the session at index.php because the session is not initialized at that point, and isn't started by reference..

Whats the error you are suppressing ?

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

Postby jasonc » Wed Apr 04, 2012 7:38 pm

It's a custom CMS. session_start() is called very early on in my main index.php. the error (Actually a warning) is "session_start has already been called".

Because it's just a warning the page continues to load, and the chat works fine. So, as you can see, its not a problem of the session not loading, or accessing the session vars because it does technically work. However, if I don't have it call session_start() a second time, even though it really doesn't "do" anything productive, the chat doesn't finish loading.
jasonc
New member
 
Posts: 4
Joined: Wed Apr 04, 2012 5:03 pm
Top

Postby re*s.t.a.r.s.*2 » Wed Apr 04, 2012 11:56 pm

Hi,

Can you put your second session call wrapped in if statement?

if the session is started somewhere in your required file then it wont fire and the session should be set.

Have you var_dump the session array without calling the session again?

Does the session is set?

Would be important to see your code..

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

Postby jasonc » Thu Apr 05, 2012 1:00 pm

most of the code is spread over a dozen class/include files. my session is set, and vars can be accessed throughout.
the include "chat.php" is extremely simple:

<?php


if(!isset($_SESSION)) {session_start(); }

$unamearry = explode(" ",$_SESSION["displayname"]);
$firstname = $unamearry[0];
$channels = array("Main");

require_once dirname(__FILE__)."/mod/chat/src/phpfreechat.class.php";
$params = array();
$params["title"] = "TWH";
$params["channels"] = $channels;
$params["nick"] = iconv("ISO-8859-1", "UTF-8", $firstname);
$params['firstisadmin'] = true;
$params["serverid"] = md5(__FILE__); // calculate a unique id for this chat
$params["debug"] = false;
$params["theme"] = "zilveer";
$params["height"] = "230px";
$chat = new phpFreeChat( $params );
?>

<div class="content">
<?php $chat->printChat(); ?>
</div>

I did wrap the session_start in an if, and it works, BUT if i do this:

var_dump($_SESSION);
if(!isset($_SESSION)) { session_start();}

the session var is dumped, but the chat never loads (Chat Loading...). So the session is obviously loaded before I even test for it, as i can dump it. but the chat doesn't seem to like output before being called.

If I output *anything* before calling the chat, it doesn't load, but if i don't make that irrelevant check for the session, it also doesn't load.

so, this works:

if(!isset($_SESSION)) {session_start(); }

this doesnt:

echo "fartknocker";
if(!isset($_SESSION)) {session_start(); }


Weird.
jasonc
New member
 
Posts: 4
Joined: Wed Apr 04, 2012 5:03 pm
Top

Postby re*s.t.a.r.s.*2 » Thu Apr 05, 2012 1:44 pm

this doesnt:
Code: Select all
echo "fartknocker";
if(!isset($_SESSION)) {session_start(); }


That above wont work because you are echoing something before starting the session..

so, this works:
Code: Select all
if(!isset($_SESSION)) {session_start(); }


If was started because the session wasn't set, then the session wasn't set...
Is very implicit either is not or is, so check your requires ...

try this at the very top of the page after just your requires

Code: Select all
if (isset($_SESSION)){
var_dump($_SESSION);
exit();
}

I'll keep checking

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

Postby jasonc » Thu Apr 05, 2012 2:23 pm

You're missing the part where the session is actually already set and used constantly before the include('chat.php');

I can call:

var_dump($_SESSION);

and it dumps the session and all its var goodness, which then prevents the chat from working.

let me put it this way...this doesn't work.. (the array is dumped successfully, but chat never loads):

if(!isset($_SESSION)) {session_start();}
var_dump($_SESSION);

And also this doesn't work (the array is dumped successfully, but chat never loads):

var_dump($_SESSION);
if(!isset($_SESSION)) {session_start();}

And also this doesn't work (the array isn't dumped because it is actually set, chat never loads):

if(!isset($_SESSION)) {session_start(); var_dump($_SESSION); }

yet somehow this does:

if(!isset($_SESSION)) {session_start();}


Its like there are 2 issues here.
1. the unnecessary check on the session makes the chat work
2. output before calling $chat = new phpFreeChat( $params ); causes the chat not to load.
jasonc
New member
 
Posts: 4
Joined: Wed Apr 04, 2012 5:03 pm
Top

Postby re*s.t.a.r.s.*2 » Thu Apr 05, 2012 3:02 pm

Ok,

Do you have a public URL, you seen any javascript error?

You 've got a very weird issue with your session..

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


Post a reply
8 posts • Page 1 of 1

Return to General Support (v1.x)

Who is online

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