Web Analytics Made Easy -
StatCounter making a register script - CodingForum

Announcement

Collapse
No announcement yet.

making a register script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • making a register script

    hi guys okay so last night i stayed up working on an uploading system.
    http://www.dangmn.net/tgl/report.php

    now can anyone tell me where / how i can get a script where i make members register before being able to upload?

    ex: if you want to upload, you must register.

    thanks!

  • #2
    Do you want a script to just register users, or do you want a 'user authentication system'. The former being the idea that the user can just register with an email address, upload a file, and have that user's info tagged for that file, the latter being a full login system, password authentication, etc.

    Neither are difficult to put together yourself with a little patience. I know there are plenty of tutorials out there on login systems.

    Comment


    • #3
      user authentication system

      what i really want is, the user to register,

      User name:
      Password:


      and they are good to log in and upload simple as that.

      Comment


      • #4
        Well make a register form like :

        Code:
              <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
        <p><input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" size="30" maxlength="30" /> <small>Username</small></p>
                 
                  <p><input type="password" name="password1" size="30" maxlength="40" /> <small>Password</small></p>
                 
                  <p><input type="password" name="password2" size="30" maxlength="40" /> <small>Confirm Password</small></p>
                 
                  <p><input type="text" name="email" size="30" maxlength="30"/> <small>Email Address</small></p>
        
                  <p><input type="submit" name="submit" value="Register" /></p>
                  <input type="hidden" name="submitted" value="TRUE" />
              </form>
        Heres a simple Registration form, now for the PHP use something like this (this is what i use and is relative to my database so change it to yours.)

        PHP Code:
        if (isset($_POST['submitted'])) {
         

            
        $errors = array();

              if (
        eregi('^[[:alnum:]\.\'\-]{4,30}$'stripslashes(trim($_POST['username']))) ) {
                      
        $user mysql_real_escape_string($_POST['username']);
                      
        $query "SELECT username FROM users WHERE username = '$user'";
                      
        $result = @mysql_query($query);
                      
        $num = @mysql_num_rows($result);
                     
                      if (
        $num0) {
                          
        $errors[] = '<font color="red">The username you have chosen has already been taken, please try again.</font>';
                      } else {
                          
        $username mysql_real_escape_string($_POST['username']);
                      }
                  } else {
                      
        $errors[] = '<font color="red">Please provide a valid username between 4 and 30 characters.</font>';
                  }

              if (!
        eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}'stripslashes(trim($_POST['email'])) )) {
                      
        $errors[] = '<font color="red">Please provide a valid email address.</font>';
                  } else {
                      
        $email mysql_real_escape_string($_POST['email']);
                  }

              if (!empty(
        $_POST['password1'])) {
                      if (
        $_POST['password1'] != $_POST['password2']) {
                          
        $errors[] = '<font color="red">The 2 passwords you have entered do not match.</font>';
                      } else {
                          
        $password md5($_POST['password1']);
                      }
                  } else {
                      
        $errors[] = '<font color="red">Please provide a password.</font>';
                  }

              if (empty(
        $errors)) {
                  
        $ip=$_SERVER['REMOTE_ADDR']; 
                      
        $query "INSERT INTO users (username, email, password, ip) VALUES ('$username', '$email', '$password', '$ip')";
                     
                      
        $result = @mysql_query($query);
                     
                      if (
        mysql_affected_rows() == 1) {
               
                                      
        // Send the E-Mail
                                      
        $body "Thank you for registering at the User Registration site.
                          mail(
        $_POST['email'], 'Registration Confirmation', $body, 'From: [email protected]');
               
                                     // Show thank you message
                          echo '<h3>Thank You!</h3>
                          You have been registered, you have been sent an e-mail to the address you specified before.
                      } else {
                          echo '<font color="
        red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>';
                      }


        } else {
            

                echo '<h3>Error!</h3>

                The following error(s) occured:<br />';

               

                foreach (
        $errors as $msg) {

                    echo " 
        - <font color=\"red\">$msg</font><br />\n";

                }

            }


        Then you must login, so make a login page with the following code :

        PHP Code:
        session_start(); // Starts the session.
        if ($_SESSION['logged'] == 1) { // User is already logged in.
            
        header("Location: index.php"); // Goes to main page.
            
        exit(); // Stops the rest of the script.
        } else {
            if (!isset(
        $_POST['submit'])) { // The form has not been submitted.
                
        echo "<form action=\"login.php\" method=\"POST\">";
                echo 
        "<table>";
                echo 
        "<tr>";
                echo 
        "<td colspan=\"2\">Login:</td>";
                echo 
        "</tr>";
                echo 
        "<tr>";
                echo 
        "<td width=\"50%\">Username:</td><td width=\"50%\"><input name=\"username\" size=\"18\" type=\"text\" />";
                echo 
        "</tr>";
                echo 
        "<tr>";
                echo 
        "<td width=\"50%\">Password:</td><td width=\"50%\"><input name=\"password\" size=\"18\" type=\"password\" />";
                echo 
        "</tr>";
                echo 
        "<tr>";
                echo 
        "<td colspan=\"2\"><input type=\"submit\" name=\"submit\" value=\"submit\"</td>";
                echo 
        "</tr>";
                echo 
        "</table>";
                echo 
        "</form>";
            } else {
                
        $username form($_POST['username']);
                
        $password md5($_POST['password']); // Encrypts the password.
                
                
        $q mysql_query("SELECT * FROM `users` WHERE username = '$username' AND password = '$password'") or die (mysql_error()); // mySQL query
                
        $r mysql_num_rows($q); // Checks to see if anything is in the db.
                
        if ($r == 1) { // There is something in the db. The username/password match up.
                  
        $_SESSION['username']=$username// new code saves username to the session variable  
                    
        $_SESSION['logged'] = 1;
                    
        header("Location: index.php"); // Goes to main page.
                    
        exit(); // Stops the rest of the script.
                
        } else { // Invalid username/password.
                    
        exit("Incorrect username/password!"); // Stops the script with an error message.
                
        }
            }
        }
        ?> 
        Ok now we are logged in, you must state on the uploader php file to display everything if the person is logged in or not.

        So now in your upload php file add at the top :

        PHP Code:
        session_start();
        if(
        $_SESSION['logged'] != 1) {
        header("Location: login.php"// redirect to login
        }else{
        // upload code

        Hope this helps!
        Last edited by Killermud; Apr 3, 2009, 02:59 PM.

        Comment


        • #5
          Here is a link to a very good login system:
          http://evolt.org/node/60384

          It's very reliable!

          Comment


          • #6
            alright thanks so much! but in the registration form, i get an error that says

            Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/dangmnne/public_html/testing/registration.php on line 49

            http://www.dangmn.net/testing/registration.php

            here's the code for registration form so far,
            PHP Code:
            <?php

            if (isset($_POST['submitted'])) {
             

                
            $errors = array();

                  if (
            eregi('^[[:alnum:]\.\'\-]{4,30}$'stripslashes(trim($_POST['username']))) ) {
                          
            $user mysql_real_escape_string($_POST['username']);
                          
            $query "SELECT username FROM users WHERE username = '$user'";
                          
            $result = @mysql_query($query);
                          
            $num = @mysql_num_rows($result);
                         
                          if (
            $num0) {
                              
            $errors[] = '<font color="red">The username you have chosen has already been taken, please try again.</font>';
                          } else {
                              
            $username mysql_real_escape_string($_POST['username']);
                          }
                      } else {
                          
            $errors[] = '<font color="red">Please provide a valid username between 4 and 30 characters.</font>';
                      }

                  if (!
            eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}'stripslashes(trim($_POST['email'])) )) {
                          
            $errors[] = '<font color="red">Please provide a valid email address.</font>';
                      } else {
                          
            $email mysql_real_escape_string($_POST['email']);
                      }

                  if (!empty(
            $_POST['password1'])) {
                          if (
            $_POST['password1'] != $_POST['password2']) {
                              
            $errors[] = '<font color="red">The 2 passwords you have entered do not match.</font>';
                          } else {
                              
            $password md5($_POST['password1']);
                          }
                      } else {
                          
            $errors[] = '<font color="red">Please provide a password.</font>';
                      }

                  if (empty(
            $errors)) {
                      
            $ip=$_SERVER['REMOTE_ADDR']; 
                          
            $query "INSERT INTO users (username, email, password, ip) VALUES ('$username', '$email', '$password', '$ip')";
                         
                          
            $result = @mysql_query($query);
                         
                          if (
            mysql_affected_rows() == 1) {
                   
                                          
            // Send the E-Mail
                                          
            $body "Thank you for registering at the User Registration site.
                              mail(
            $_POST['email'], 'Registration Confirmation', $body, 'From: [email protected]');
                   
                                         // Show thank you message
                              echo '<h3>Thank You!</h3>
                              You have been registered, you have been sent an e-mail to the address you specified before.
                          } else {
                              echo '<font color="
            red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>';
                          }


            } else {
                

                    echo '<h3>Error!</h3>

                    The following error(s) occured:<br />';

                   

                    foreach (
            $errors as $msg) {

                        echo " 
            - <font color="red\">$msg</font><br />\n";

                    }

                }

            }

            ?>

            and in my register form it works but once you fill out all the fields when you press "register" it doesn't go anywhere.
            http://www.dangmn.net/testing/register.php

            PHP Code:
                  <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
            <p><input type="text" name="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>" size="30" maxlength="30" /> <small>Username</small></p>
                     
                      <p><input type="password" name="password1" size="30" maxlength="40" /> <small>Password</small></p>
                     
                      <p><input type="password" name="password2" size="30" maxlength="40" /> <small>Confirm Password</small></p>
                     
                      <p><input type="text" name="email" size="30" maxlength="30"/> <small>Email Address</small></p>

                      <p><input type="submit" name="submit" value="Register" /></p>
                      <input type="hidden" name="submitted" value="TRUE" />
                  </form>

            Comment


            • #7
              Try this:
              PHP Code:
              <?php 

              if (isset($_POST['submitted'])) { 
                

                  
              $errors = array(); 

                    if (
              eregi('^[[:alnum:]\.\'\-]{4,30}$'stripslashes(trim($_POST['username']))) ) { 
                            
              $user mysql_real_escape_string($_POST['username']); 
                            
              $query "SELECT username FROM users WHERE username = '$user'"
                            
              $result = @mysql_query($query); 
                            
              $num = @mysql_num_rows($result); 
                            
                            if (
              $num0) { 
                                
              $errors[] = '<font color="red">The username you have chosen has already been taken, please try again.</font>'
                            } else { 
                                
              $username mysql_real_escape_string($_POST['username']); 
                            } 
                        } else { 
                            
              $errors[] = '<font color="red">Please provide a valid username between 4 and 30 characters.</font>'
                        } 

                    if (!
              eregi('^[a-zA-Z]+[a-zA-Z0-9_-]*@([a-zA-Z0-9]+){1}(\.[a-zA-Z0-9]+){1,2}'stripslashes(trim($_POST['email'])) )) { 
                            
              $errors[] = '<font color="red">Please provide a valid email address.</font>'
                        } else { 
                            
              $email mysql_real_escape_string($_POST['email']); 
                        } 

                    if (!empty(
              $_POST['password1'])) { 
                            if (
              $_POST['password1'] != $_POST['password2']) { 
                                
              $errors[] = '<font color="red">The 2 passwords you have entered do not match.</font>'
                            } else { 
                                
              $password md5($_POST['password1']); 
                            } 
                        } else { 
                            
              $errors[] = '<font color="red">Please provide a password.</font>'
                        } 

                    if (empty(
              $errors)) { 
                        
              $ip=$_SERVER['REMOTE_ADDR'];  
                            
              $query "INSERT INTO users (username, email, password, ip) VALUES ('$username', '$email', '$password', '$ip')"
                            
                            
              $result = @mysql_query($query); 
                            
                            if (
              mysql_affected_rows() == 1) { 
                      
                                            
              // Send the E-Mail 
                                            
              $body "Thank you for registering at the User Registration site. ";
                                
              mail($_POST['email'], 'Registration Confirmation'$body'From: [email protected]'); 
                      
                                           
              // Show thank you message 
                                
              echo '<h3>Thank You!</h3> 
                                You have been registered, you have been sent an e-mail to the address you specified before. '
              ;
                            } else { 
                                echo 
              '<font color="red">You could not be registered, please contact us about the problem and we will fix it as soon as we can.</font>'
                            } 


              } else { 
                   

                      echo 
              '<h3>Error!</h3> 

                      The following error(s) occured:<br />'


                      

                      foreach (
              $errors as $msg) { 

                          echo 
              " - <font color="red\">$msg</font><br />\n"

                      } 

                  } 



              ?>

              Comment


              • #8
                here's the register page now: http://www.dangmn.net/tgl/login.php

                but now i get an error that says: No database selected

                here is the script to my other.php


                PHP Code:
                <?php

                session_start
                ();     //note session here
                //set local variables

                $dbhost "localhost"
                $dbuser "dangmnne_setname"
                $dbpass "abc123"
                $dbname "dangmnne_setname"

                //connect 
                $db mysql_pconnect($dbhost,$dbuser,$dbpass); 
                mysql_select_db("$dbname",$db); 


                //Add DB info here
                   
                $setname =  $_POST['setname'];
                $password =  $_POST['password'];
                $aka $_POST['aka'];

                   
                $query "Select * FROM members WHERE setname = '".$setname."'";
                   
                $result3 mysql_query($query) or die(mysql_error());
                   
                $name3 mysql_fetch_array($result3);
                        
                $setname1 $name3[setname];
                   
                   
                $setname2 strtolower($setname);
                   
                $setname3 strtolower($setname1);
                   
                      if(
                strcmp($setname2$setname3) != 0)
                   {
                      if(
                strcmp($password"") != 0)
                      
                      {      
                      
                      
                      if(
                strcmp($aka"") != 0)
                      {
                         
                         echo 
                'Congratulations <b> ' .$setname'</b> you have Successfully registered <br>';
                         echo 
                'You should now be logged in';
                         
                         
                //do everything
                         
                         
                $_SESSION['user'] = $setname//ADDS THE SESSION
                                  
                         
                $date date("d-m-y");
                         
                $query "INSERT INTO members (Date,  setname, setnamecolor, password, aka,)
                VALUES ('"
                .$date."', '".$setname."', '".$setname."', '".$password."', '".$aka."')";

                $result mysql_query($query) or die(mysql_error());

                mysql_close($db);
                            
                                  }
                      else
                      {
                         echo 
                'Please enter at the least the first aka spot';
                      }
                      }
                      else
                      {
                         echo 
                'Please enter a password';
                      }
                   }
                   else
                   {
                      echo 
                'SET name is already registered';
                   }
                   
                ?>
                do you see any idea how i can fix this error? thanks

                Comment


                • #9
                  Try this:
                  PHP Code:
                  <?php

                  session_start
                  ();     //note session here
                  //set local variables

                  $dbhost "localhost"
                  $dbuser "dangmnne_setname"
                  $dbpass "abc123"
                  $dbname "dangmnne_setname"

                  //connect 
                  $db mysql_connect($dbhost,$dbuser,$dbpass); 
                  mysql_select_db("$dbname",$db); 


                  //Add DB info here
                     
                  $setname =  $_POST['setname'];
                  $password =  $_POST['password'];
                  $aka $_POST['aka'];

                     
                  $query "Select * FROM members WHERE setname = '".$setname."'";
                     
                  $result3 mysql_query($query) or die(mysql_error());
                     
                  $name3 mysql_fetch_array($result3);
                          
                  $setname1 $name3[setname];
                     
                     
                  $setname2 strtolower($setname);
                     
                  $setname3 strtolower($setname1);
                     
                        if(
                  strcmp($setname2$setname3) != 0)
                     {
                        if(
                  strcmp($password"") != 0)
                        
                        {      
                        
                        
                        if(
                  strcmp($aka"") != 0)
                        {
                           
                           echo 
                  'Congratulations <b> ' .$setname'</b> you have Successfully registered <br>';
                           echo 
                  'You should now be logged in';
                           
                           
                  //do everything
                           
                           
                  $_SESSION['user'] = $setname//ADDS THE SESSION
                                    
                           
                  $date date("d-m-y");
                           
                  $query "INSERT INTO members (Date,  setname, setnamecolor, password, aka,)
                  VALUES ('"
                  .$date."', '".$setname."', '".$setname."', '".$password."', '".$aka."')";

                  $result mysql_query($query) or die(mysql_error());

                  mysql_close($db);
                              
                                    }
                        else
                        {
                           echo 
                  'Please enter at the least the first aka spot';
                        }
                        }
                        else
                        {
                           echo 
                  'Please enter a password';
                        }
                     }
                     else
                     {
                        echo 
                  'SET name is already registered';
                     }
                     
                  ?>
                  You mis-spelled mysql_connect

                  Comment


                  • #10
                    lol! oh my god, ok now i fixed that, and now i get

                    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'dangmnne_setname'@'localhost' (using password: YES) in /home/dangmnne/public_html/tgl/other.php on line 12

                    Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/dangmnne/public_html/tgl/other.php on line 13

                    Warning: mysql_query() [function.mysql-query]: Access denied for user 'dangmnne'@'localhost' (using password: NO) in /home/dangmnne/public_html/tgl/other.php on line 23

                    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/dangmnne/public_html/tgl/other.php on line 23
                    Access denied for user 'dangmnne'@'localhost' (using password: NO)

                    Comment


                    • #11
                      Those warning are occurring because that user either doesn't exist, the password is incorrect or doesn't have privileges for that database. Have you created a database user called dangmnne_setname with the password abc123. You may want to go into phpMyAdmin and check if that user exists. If not create it and give it the privileges for SELECT, INSERT and UPDATE. Also make sure you have created a database called dangmnne_setname. Again you can do that in phpMyAdmin. And finally you will have to create your table members with the following fields Date, setname, setnamecolor, password, aka. Again can be done in phpMyAdmin.

                      Also your code is very insecure. You need to validate user submitted data or you WILL get hacked via SQL injections and password should not be stored in plain text. They have to be hashed before being inserted to the database.
                      You can not say you know how to do something, until you can teach it to someone else.

                      Comment


                      • #12
                        oh my god i finally got it!!

                        Congratulations SuBZero[STFU] you have Successfully registered
                        You should now be logged in

                        You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES ('04-04-09', 'SuBZero[STFU]', 'SuBZero[STFU]', 'ddd', 'darkknight')' at line 1

                        but i have that tiny error. what was that about?

                        Comment


                        • #13
                          Find this:
                          PHP Code:
                                   //do everything 
                                    
                                   
                          $_SESSION['user'] = $setname//ADDS THE SESSION 
                                             
                                   
                          $date date("d-m-y"); 
                                   
                          $query "INSERT INTO members (Date,  setname, setnamecolor, password, aka,) 
                          VALUES ('"
                          .$date."', '".$setname."', '".$setname."', '".$password."', '".$aka."')"

                          $result mysql_query($query) or die(mysql_error()); 

                          mysql_close($db); 
                          AND CHANGE IT TO:
                          PHP Code:
                                   //do everything 
                                    
                                   
                          $_SESSION['user'] = $setname//ADDS THE SESSION 
                                             
                                   
                          $date date("d-m-y"); 
                                   
                          $query "INSERT INTO members (Date,  setname, setnamecolor, password, aka) 
                          VALUES ('"
                          .$date."', '".$setname."', '".$setname."', '".$password."', '".$aka."')"

                          $result mysql_query($query) or die(mysql_error()); 

                          mysql_close($db); 

                          Comment


                          • #14
                            thanks allot

                            Congratulations Mutalisk[stfu] you have Successfully registered
                            You should now be logged in


                            alright so each time a member sign up, their user name will be stored in my database now right?

                            and one more thing, after they sign up, is there a way for me to add the "upload" page where they upload things since they are signed up now?

                            ex: i want that to display right after they signed up
                            http://www.dangmn.net/tgl/upload.php
                            Last edited by LambofGod; Apr 5, 2009, 12:59 AM.

                            Comment


                            • #15
                              nobody?

                              Comment

                              Working...
                              X