|
|
|
|
![]() ![]() |
![]() ![]() Group: Members
Posts: 36 Joined: 22-July 04 Member No.: 165 |
Post
#1
Aug 4 2004, 08:15 PM
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. |
![]() ![]() ![]() Group: Members
Posts: 45 Joined: 4-August 04 Member No.: 667 |
Post
#2
Aug 4 2004, 10:44 PM
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.
|
![]() Group: Members
Posts: 16 Joined: 24-July 04 Member No.: 190 |
Post
#3
Aug 4 2004, 11:33 PM
to put something in the session CODE $_SESSION['variable_name'] = "some_value"; make sure you do not do the following CODE $variable_name = "another value"; in any part of ur page it will overwrite the value in ur $_SESSION['variable_name'] |
![]() ![]() Group: Members
Posts: 32 Joined: 30-January 05 Member No.: 3,494 |
Post
#4
Feb 1 2005, 05:05 AM
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> QUOTE(triax @ Aug 4 2004, 06:33 PM) to put something in the session
CODE $_SESSION['variable_name'] = "some_value"; make sure you do not do the following CODE $variable_name = "another value"; in any part of ur page it will overwrite the value in ur $_SESSION['variable_name'] [right][snapback]4054[/snapback][/right] |
![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 119 Joined: 12-July 04 From: london Member No.: 85 |
Post
#5
Feb 1 2005, 11:07 PM
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.. CODE <?php session_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 CODE <?PHP session_start(); var_dump($_SESSION); ?> YOU WILL see that you have the variable username in the session array. hope this helps |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 624 Joined: 30-October 04 From: Philippines Member No.: 2,049 |
Post
#6
Feb 5 2005, 05:34 AM
Don't use sessions. Use Cookies. Use it something like this: CODE <?php if (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. |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 482 Joined: 11-October 04 Member No.: 1,665 |
Post
#7
Feb 5 2005, 07:49 AM
or u can try to disable session id ? try to insert this into the .htaccess file : CODE php_flag session.use_trans_sid off
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED]
Posts: 590 Joined: 4-November 04 From: Novi Sad, Vojvodina Member No.: 2,127 |
Post
#8
Feb 6 2005, 03:29 PM
QUOTE(karlo @ Feb 5 2005, 05:34 AM) Don't use sessions. Use Cookies. [right][snapback]46735[/snapback][/right] And what if user has disabled cookies in his browser? CODE Header('Location: somepage.php?'.SID); Then in that file call session_start(); and use $_SESSION array to access session variables... That HAS to work |
![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 114 Joined: 9-August 04 From: Suzhou Jiangsu China Member No.: 743 |
Post
#9
Feb 7 2005, 02:54 AM
SESSION stored on server COOKIES stored on client session is safer than cookies |
![]() ![]() |
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
7 | -ivanc081- | 1,698 | 15th December 2007 - 12:15 AM Last post by: hippiman |
|||
![]() |
5 | electron | 468 | 3rd July 2006 - 06:52 AM Last post by: electron |
|||
![]() |
2 | fsoftball | 1,140 | 9th May 2005 - 08:09 AM Last post by: mobious |
|||
![]() |
0 | kvarnerexpress | 866 | 23rd July 2005 - 01:21 PM Last post by: kvarnerexpress |
|||
![]() |
1 | apple | 506 | 25th September 2006 - 08:04 AM Last post by: slu |
|||
![]() |
0 | ghostrider | 500 | 28th April 2007 - 02:35 AM Last post by: ghostrider |
|||
![]() |
0 | sinisteredd | 318 | 8th April 2008 - 06:55 PM Last post by: sinisteredd |
|||
![]() |
1 | sonesay | 424 | 21st December 2007 - 11:46 AM Last post by: shadowx |
|||
![]() |
4 | ghostrider | 401 | 10th February 2008 - 04:40 AM Last post by: FLaKes |
|||
|
Open Discussion | Time is now: 8th January 2009 - 09:48 AM |