anyone want to give me some guidelines on a simple login/register page?

like signup.php would ask you to choose a user/pass and checks if user is not already taken, then you will be added to the database..

and then login.php would ask for the user name and pass... then it would take you to index.php and say "Welcome, [username]"

or maybe someone could point me to a good tutorial on this

im the biggest n00b of php so make it as easy as possible, gracias
:rolleyes:

    LOL no i don't know spanish i just said gracias cause im 1337 like that... i need one in english

      This should be a good starter project to bring you out of "biggest n00b" status.

      You're going to want to learn about sessions and MySQL (assuming that's the db you're using) database queries. Learn about sessions here: http://www.php.net/manual/en/ref.session.php , and mysql functions here: http://www.php.net/manual/en/ref.mysql.php .

      Here is some pseudo code to get you started:

      
      session_start(); 
      session_register('username'); 
      session_register('password');
      
      $cid = mysql_connect("localhost", "yourusername", "yourpassword");
      
      if (isset($username)) {
      $sql = " SELECT * from database.users_table WHERE username = '$username' ";
      
      $retid = mysql_query($sql, $cid); 
      $row = mysql_fetch_array($retid); 
      $checkpassword = $row["password"]; 
      if ($checkpassword == $password) {
      echo("Welcome $username");
      }
      else {
      echo("authentication failed"); 
      }
      }
      else {
      // Output login page
      }
      
      

      That should get you started. The code may have errors, since I wrote it in about 2 minutes, so I wouldn't use it as is, just use it to get a feel for what you need to do.

        codit: that really helps alot but could i ask one thing from u

        if you could please add //comments to each line of the code u made breifly explaining what it does... that would be great (there are a few things in that code that confuse me, i just want to see what they do)

          
          // Initialize the session 
          session_start(); 
          // Register the session variables 'username' and 'password'
          session_register('username'); 
          session_register('password');
          
          // Connect to the mysql database
          $cid = mysql_connect("localhost", "yourusername", "yourpassword");
          
          // Check to see if the username var is set
          // This could be done a number of different ways, for example you
          // could check the request method (POST), or your login form 
          // could set another variable, like 'dologin' or something
          if (isset($username)) {
          // Setup SQL query
          $sql = " SELECT * from database.users_table WHERE username = '$username' ";
          // Query the database
          $retid = mysql_query($sql, $cid); 
          // Get results
          $row = mysql_fetch_array($retid); 
          // Check the password the user supplied against the stored password
          $checkpassword = $row["password"]; 
          if ($checkpassword == $password) {
          echo("Welcome $username");
          }
          else {
          echo("authentication failed"); 
          }
          }
          // Output the login page if nothing was posted to the script
          else {
          // Output login page
          }
          
          

          I hope that helps. Basically for this to work you'd have a table setup in your database that holds the username, password, and an ID. The sql stuff I did basically gets the information about whatever username the user specified, and then checks the password against it. Also, by using sessions you have the ability to use the script on multiple pages... the session vars will be stored on the server (referenced by a cookie or GET type session ID).

            Also, I forgot to mention. You may need to add a couple lines like this:

            $username = $_POST['username'];
            $password = $_POST['password'];
            

            You would need this if register globals is off. I leave it on, on my server so I don't usually bother with it. It basically takes the username and password posted to the script by your login form and sets it to regular vars. Of course you could just simply use the "long" versions of the vars ($_POST['var']), but for simplicity sake I always initialize post vars to a regular var when needed.

              WELL>>>>>

              I am using this:

              <?
              
              
              $cid = mysql_connect("localhost", "mylogin", "myp***");
              
              
              $sql = " SELECT * from nibode.Contacts WHERE Email = '$email' ";
              
              $retid = mysql_query($sql, $cid); 
              $row = mysql_fetch_array($retid); 
              $checkpassword = $row["Password"]; 
              
              if ($checkpassword == $password) {
              
              echo("Welcome $email");
              }
              else {
              
              echo("authentication failed $email $sql"); 
              }
              
              
              
              ?>
              
              hello
              

              and it is giving me this error:

              Warning: 0 is not a MySQL result index in /u/htdocs/.../login.php on line 10
              authentication failed test SELECT * from Contacts WHERE Email = 'test' hello

                Write a Reply...