jailbox 0 Report post Posted August 4, 2004 Hi. Im making a flatfile chatroom. Ive been making it about a month because I dont understand the sessions. When the user enters the room he/she has to enter a nickname. But when the user enters a message the chatroom "forgets" the nickname. Ive been messing around with sessions but I cant get em to work. Session_start(); thingy is in the right place (at the top). Ive looked through about 10 diferent tutorials but they were useless. How do I make it to pass the nickname variable to multiple pages?And please dont tell me to search google or use php.net because ive already used those. Share this post Link to post Share on other sites
Gamesquare 0 Report post Posted August 4, 2004 What's the link to the chatroom, and could you post the source code? It would be easier to figure out what's wrong if we could see what you're trying. Share this post Link to post Share on other sites
triax 0 Report post Posted August 4, 2004 to put something in the session $_SESSION['variable_name'] = "some_value";make sure you do not do the following$variable_name = "another value";in any part of ur pageit will overwrite the value in ur $_SESSION['variable_name'] Share this post Link to post Share on other sites
jordanliuhao 0 Report post Posted February 1, 2005 I'd like to use session_register <?php if (!session_is_registered('count')) { session_register('count'); $count = 1; } else { $count++; } ?> <p> Hello visitor, you have seen this page <?php echo $count; ?> times. </p> <p> To continue, <a href="nextpage.php?<?php echo strip_tags(SID); ?>">click here</a>. </p> to put something in the session $_SESSION['variable_name'] = "some_value";make sure you do not do the following $variable_name = "another value";in any part of ur pageit will overwrite the value in ur $_SESSION['variable_name'] 4054[/snapback] Share this post Link to post Share on other sites
stevey 0 Report post Posted February 1, 2005 php sessions may be tricky thats why in order to be absolutely sure you have to completely register the session below is a script that will register the username variable and will be accesssesible throughout the other pages.. <?phpsession_start();session_register('username');$_SESSION['username'] = $username;?>by doing this then in all other pages below the page that you registered this. the variable username will be available, to test this create another page and do this<?PHPsession_start();var_dump($_SESSION);?>YOU WILL see that you have the variable username in the session array. hope this helps Share this post Link to post Share on other sites
karlo 0 Report post Posted February 5, 2005 Don't use sessions. Use Cookies.Use it something like this: <?phpif (isset($_COOKIE["user"])){?><h3>Welcome back, <span style="color: red;"><?php print $_COOKIE["user"]; ?></span></h3><?php}else {?><form name="form1" method="get">Enter your username: <input name="username" size="15"><br><br><span style="color: blue; cursor: pointer;" onclick="form1.submit()">Submit</span></form><?php}if (isset($_GET["username"])){setcookie("user",$_GET["username"],time()+9999); //set cookie to expire at that time you can experiment and add more ++ if you want?><h3>Username set!</h3><script language="javascript" type="text/javascript">setTimeout("window.location='./';",2000);</script><?php}?> Tell me if there's an error and I will correct it. Share this post Link to post Share on other sites
ashiezai 0 Report post Posted February 5, 2005 or u can try to disable session id ?try to insert this into the .htaccess file : php_flag session.use_trans_sid off Share this post Link to post Share on other sites
Galahad 0 Report post Posted February 6, 2005 Don't use sessions. Use Cookies. 46735[/snapback] And what if user has disabled cookies in his browser? Then it won't work. The vest way is to... well, there is actualy a best way, but... just append sessionid when calling a new scrpt: Header('Location: somepage.php?'.SID); Then in that file call session_start(); and use $_SESSION array to access session variables... That HAS to work Share this post Link to post Share on other sites
LuciferStar 0 Report post Posted February 7, 2005 SESSION stored on serverCOOKIES stored on clientsession is safer than cookies Share this post Link to post Share on other sites