i'm trying to set session variable $userid and $user_level

it seems that it should written like:

$userid=abc
$user_level=pwd
session_start()
session_register($userid);
session_register($user_level);

then how i echo them so that i feel sure the session variable had set?

is it just
echo $userid;
echo $user_level;

??........it look i'm echo the variable set at the beginning!

    Hi,

    When doing your session_register() :

    session_register('s_userid');

    $s_userid = $userid;

    then

    echo $s_userid;

    Give that a go...

      tks..
      i'm waiting....ans!

        notice, that sessio_register("variable") <- variable is withour $ sign.

          i've try it ....
          and get error....
          though $s_user and $s_level can echo out...
          but ...still hav error....

          it is on the line of session_start....

          the prog is:

          <body bgcolor="#FF9900" text="#333333" link="#FFFF00" alink="#666600" vlink="#FFCC66">
          <div align="center">
          <font size="6">«Où²Õ</font>
          <img src="clccccphoto1.jpg" width="200" height="130"><br>
          <form method="post" action="paullink.php">

          <?php
          $form_user="paul";
          $success=0;
          require 'common.inc' ;

          $query="select * from user where name='$form_user' and password='$form_password'";

          mysql_connect($host,$user,$password);
          mysql_select_db($database);
          $query = stripSlashes($query);
          $result = mysql_query($query);

          if ($row = mysql_fetch_array($result)){
          	if($row["level"]==3 || $row["level"]==4){
          	$success=1;
          	session_start();                                    //line 13
          	if (session_register("s_user") && session_register("s_level")){
          			$s_user=$form_user;
          			$s_level=$row['level'];
          			echo $s_user;
          			echo $s_level;}
          
          }}

          ?>

          error msg is

          Warning: Cannot send session cookie - headers already sent by (output started at /home/clc/www/html/paullink.php:13) in /home/clc/www/html/paullink.php on line 28

          Warning: Cannot send session cache limiter - headers already sent (output started at /home/clc/www/html/paullink.php:13) in /home/clc/www/html/paullink.php on line 28
          paul3

          the paul3 is the echoes...

            The problem is you are having your sessions registered and started inside the if statement that can happen numerous times.

            Do

            session_start();

            at the start of your program first.

            Then another problem...

            if (session_register("s_user") && session_register("s_level")){

            Do you mean that if there is a value in these session variables do the following? Or are you trying to register them at that moment?

            I would sughgest registering them before the code under the session_start();

            Then just assign the variables to the session variables:

            $s_user=$form_user;
            $s_level=$row['level'];

            Good luck

              tks so much....i will try!

                Sigh, stop using this register_session() crap.

                Try this...

                $userid = 'abc';
                $user_level = 'pwd';
                session_start();
                $_SESSION['userid'] = $userid;
                $_SESSION['user_level'] = $user_level;
                echo 'User ID: ' . $_SESSION['userid'] . '<br>';
                echo 'User level: ' . $_SESSION['user_level'];
                

                  Originally posted by intenz
                  Sigh, stop using this register_session() crap.

                  Try this...

                  $userid = 'abc';
                  $user_level = 'pwd';
                  session_start();
                  $_SESSION['userid'] = $userid;
                  $_SESSION['user_level'] = $user_level;
                  echo 'User ID: ' . $_SESSION['userid'] . '<br>';
                  echo 'User level: ' . $_SESSION['user_level'];
                  

                  [/B]

                  The reason why this is better is that it's a bit more secured. If you don't have PHP > 4.06 then use $HTTP_SESSION_VARS instead of $_SESSION.

                    Warning: Cannot send session cookie - headers already sent by (output started at /home/clc/www/html/paullink2.php:13) in /home/clc/www/html/logsession.php on line 5

                    Warning: Cannot send session cache limiter - headers already sent (output started at /home/clc/www/html/paullink2.php:13) in /home/clc/www/html/logsession.php on line 5

                    is the above error indicated that i cannot set cookie??

                    it is the line 5....written "session start()"

                      Jael,

                      Make sure you have no spaces or carriage returns before you write your code.

                      Intenz - thanks for the handy tip, that register_session() is crap, I'll keep that in mind the next time 😃

                        your session initialization has to be done before you send any html back to the client or the headers are already sent and you get that error... there is no reason you can't move your code to the start of the script (before any HTML or echo/print code)... should work a bit better

                          do u mean that :

                          i should write;

                          <?php
                          session_start();
                          ?>
                          <html>
                          <head></head>
                          ..........

                          like this??

                          actually the webadmin told me that i can use session....
                          but is there any way to check if i canuse session....
                          coz i doubt that ......
                          tks...

                            set a session variable (after starting a session) in one page and display it in another...
                            foo.php
                            $HTTP_SESSION_VARS["blah"] = "test";

                            bar.php
                            echo $HTTP_SESSION_VARS["blah"];

                              hi everyone...

                              i've try all Bunkermaster's suggestion and it didn't work....

                              then my friend told me a way to check the config of the server...

                              <?php
                              phpinfo();
                              ?>

                              by this little program, i found that:

                              though session is enabled, but i cannot access tmp folder(no right).....so i still cannot use session.........

                              i think the webmaster is not very familiar with config php...

                              so thanks u a lot....!

                              i will use cookie.....

                                Write a Reply...