Sessions - heeeelllllp!!!!!!

free web hosting
Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Sessions - heeeelllllp!!!!!!

jailbox
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.

Reply

Gamesquare
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.

Reply

triax
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']

Reply

jordanliuhao
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']
*

 

 

 


Reply

stevey
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

Reply

karlo
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.

Reply

ashiezai
or u can try to disable session id ?

try to insert this into the .htaccess file :

CODE
php_flag session.use_trans_sid off

Reply

Galahad
QUOTE(karlo @ Feb 5 2005, 05:34 AM)
Don't use sessions. Use Cookies.
*




And what if user has disabled cookies in his browser? wink.gif 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:

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 smile.gif

Reply

LuciferStar
SESSION stored on server
COOKIES stored on client
session is safer than cookies

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : sessions heeeelllllp

  1. Something I Discovered With Sessions [php] - (4)
  2. Php Sessions And Post Variables Issues - My script dosent seem to work as intended (1)
    You can test it out for yourself at http://sonesay.trap17.com/application.php I've been
    working on this page locally and it seems to be working fine but when I upload it to my trap17
    account the post variables dont get saved properly. Fill in some fields and submit it, the form
    will come up as a empty field yet when you resubmit it without any modifications and the data you
    entered in orginally will now magically appear, resubmit it again and it will be gone. This is
    really annoying as I have no clue why it would be doing this when it seems to work fine locally....
  3. <?php ?> Unique Visitors Script - Flat file unique visitors script (no sessions) (2)
    This is really simple script. Well at least this part is, but it could be extendable. Only problem
    is that it's not really for massive websites with hundread of visitors a day, but rather for
    small ones. But it is a good script to figure out how to make a visitor counter script. Anyway
    here's the snippet. CODE <?php function getVisits($variable) {
        $visits = array();     if ($handle =
    opendir('stats/')) {     while (false !== ($file =
    readdir($handle))) {  ...
  4. Using Sessions Instead Of Cookies, Help Please - (1)
    This is a simple code to register and login.. this uses cookies.. i want to use sessions instead..
    can someone tell how i can do it ? config.php CODE <?    ob_start(); // allows you
    to use cookies    $conn =
    mysql_connect("localhost","USER","PASSWORD");   
    mysql_select_db(DATEBASE) or die(mysql_error());    //fill in the above
    lines where there are capital letters.    $logged = MYSQL_QUERY("SELECT * from users
    WHERE id='$_COOKIE[id]' AND password = '$...
  5. Sessions And Login - Without Cookies (5)
    Hi, I have a login script i made using PHP sessions and MySQL. It works fine but there is a
    problem. As you know Sessions are stored in Cookies by PHP. So if someone has switched Cookies off
    then no sessions will work. How to solve this problem ? Please help me. Thanks and have a good
    day. ...
  6. Session Variables - Sessions in PHP behaving strangely (4)
    Hi. I am part of a development team working in PHP and MySQL. The site is using SSL, and users
    have to log to use the site. When users log in, their important details are retrieved from the
    database and stored in session variables (functionality in the site is permissions specific).
    Lately, sessions are "disappearing" for no apparent reason. Users will log in, and at some point
    (the length of time will vary unpredicatably) the sessions will lose their value (the variables are
    empty) and this causes the site to evict the user. This is very frustrating for the user b...
  7. Php Sessions - Multiple users using the same login (2)
    Hi, I'm realtively new to PHP and I'm considering creating some login functionality.
    However I want a group of users to use the same loginname and password. They will be loggin infrom
    different machines. The users will know they are sharing the account. Can anyone give me an idea
    of what kind of effect this might have on my sessions? Will it create any odd hiccups or other
    strange things?...



Looking for sessions, heeeelllllp

Searching Video's for sessions, heeeelllllp
advertisement



Sessions - heeeelllllp!!!!!!



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE