Hey out there 🙂
I don't know.. this might should have been in the newbie section...
Here it comes 🙂
I've made a Login / Register script.

I have an error;

Notice: Undefined variable: _SESSION in c:\xx\usersfiles.php on line 2

I belive my problem is that the variable is not defined, when user is not logged in.

I guess it'd be easier, if you could see my scripts... 🙂
Please respond to this message, if you want the scripts, to help me 😃

EDIT::
The thing I belive would help is like the command in VB,
If Error then...
If not logged in then...
know what I'm saying? 🙂

    umm... PHP varabiables take on the form of
    $[a-zA-Z\x7f-\xff][a-zA-Z0-9\x7f-\xff]*

    So "SESSION" is not a variable, but a string. "$SESSION" would be a variable.

    Try changing SESSION to $SESSION in your code.

    Read up on [man]variables[/man] in the PHP manual as well.

    ~Brett

      looks like you are not calling [man]session_start[/man]

        Hey again 😉
        I don't know thease forums very well, and I don't know if you are used to do stuff like this, but I'll ask you to have a look at my code 🙂

        Thank you soo much, if you take your time and have a look at my code 😃

        This means alot to me 🙂

        Regards
        WhOOt

          usersfiles.php should be:

          <?php
          session_start();
          echo $_SESSION['username']."'s Files";
          ?>

          loginner.php should start like this:

          <?php
          if ($_POST['username']) 
          {
          
          session_start();
          		echo '<style type="text/css">
          <!--
          .style1 {font-size: 14px}
          -->
          </style>
           <span class="style1">';
          // set your infomation.
          $dbhost='localhost';
          $dbusername='root';
          $dbuserpass='';
          $dbname='users';
          
          
          
          // connect to the mysql database server.
          mysql_connect ($dbhost, $dbusername, $dbuserpass);
          mysql_select_db($dbname) or die('Cannot select database');
          
          //did they supply a password and username
          $username=$_POST['username'];
          $password=$_POST['password'];
          if ($password==NULL) {
          	echo "A password was not supplied";
          }else{
          	$query = mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error());
          	$data = mysql_fetch_array($query);
          	if($data['password'] != $password) {
          		echo "The supplied login is incorrect";
          	}else{
          		$query = mysql_query("SELECT username,password FROM users WHERE username = '$username'") or die(mysql_error());
          		$row = mysql_fetch_array($query);
          		$_SESSION["s_username"] = $row['username'];
          	}
          }
          echo "Logged in as ".$_SESSION['s_username']." <a href='logout.php'>LogOut</a>.";
          echo '</span>';
          }
          else
          {
          ?>
          
          <h1 class="style1">Login</h1>
                <form action='index.php' method='POST' class="style1">
                  <table style='border:1px solid #000000;'>
                    <tr>
                      <td align='right'> Username:
                          <input type='text' size='15' maxlength='25' name='username'>
                      </td>
                    </tr>
                    <tr>
                      <td align='right'> Password:
                          <input type='password' size='15' maxlength='25' name='password'>
                      </td>
                    </tr>
                    <tr>
                      <td align='center'>
                        <input name="submit" type="submit" value="Login">
                      </td>
                    </tr>
                    <tr>
                      <td align='center'> <a href='register.php'>Register Here</a> </td>
                    </tr>
                  </table>
                  <p>
          		<?
          
          	?>
          	&nbsp;</p>
            </form>
          <?
          }
          ?>

          Devinemke was right... you were missing the session_start()....

          ~Brett

            bpat1434 wrote:

            usersfiles.php should be:

            Devinemke was right... you were missing the session_start()....

            ~Brett

            Thanks for looking at my code 🙂

            But still, I have some problems 🙁

            Thanks again 🆒
            WhOOt

              Stop posting links and the like... just post the relevent code. Your meant to try and make it easy for us to help you!

                thorpe wrote:

                Stop posting links and the like... just post the relevent code. Your meant to try and make it easy for us to help you!

                Sorry, but thats what I intented to do...

                The pictues shows you the excact error. Isn't thats what helps you to help me the most?

                Thanks

                (By the way, I posted my code in a zip just a few posts up..)

                  Read up in the manual on [man]session_start[/man]. It has to be the first line, and nothing can be sent to the browser first (inlcuding HTML). Otherwise, you get that error.

                  ~Brett

                    Write a Reply...