Web Analytics Made Easy -
StatCounter php login - CodingForum

Announcement

Collapse
No announcement yet.

php login

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

  • php login

    how can we do a box of login and pass in php? thanks

  • #2
    Hi

    Have a look at this

    http://www.evolt.org/article/PHP_Log...265/index.html

    thanks
    pete

    Comment


    • #3
      ok.thanks

      Comment


      • #4
        Well I dunno if this is a sly way of spamming or not, but all your site is is an archive of different sites, which to me means you're spamming.

        Comment


        • #5
          Re: hi devil_online

          Originally posted by scriptsandcodes
          I hooked up a new database of webbased tutorials (html, php, javascript, mysql and many more - over 5000 links)

          Have a look at www.*******************

          Thanks,
          off the topic but i suggest you categorize your links, its just a huge mass that noone will read, especially not lazy ppl like me
          php & asp tutorials - the birthplace - biorust - photoshop and web technologies

          Comment


          • #6
            Here's a rough bit of code scratched up for another thread:

            Code:
            <body>
            <form action="process.php" method="POST">
            Username<br />
            <input name="username" type="text" size="30" /><br />
            Password<br />
            <input name="password" type="password" size="30" /><br />
            <input type="submit" value="Submit" /><input type="reset" value="Reset" /></form>
            </body>
            then, in process.php:

            PHP Code:
            <?php

            /**** Dump the data to a text file ****/

            // the text file to store the information
            $datafile "textfile.txt";

            // open a file handle
            $my_file fopen($datafile,"a");

            //write teh data to the file
            fputs($my_file,"Username: " $_POST["username"] . " | Password: " $_POST["password"] . "\r\n",4096);

            // close the file handle
            fclose($my_file);


            /**** Display the information in the browser ****/
            print "<html>\n\n<body>\n\n";
            print 
            "Username: " $_POST["username"];
            print 
            "<br/>\n";
            print 
            "Password: " $_POST["password"];
            print 
            "<br/>\n";
            print 
            "</body>\n\n</html>";

            ?>

            I didn't include any error handling, but the rough code should work.

            Personally, I'd encrypt the password. You could md5 it, but that really isn't nearly as secure as an encryption cipher

            Comment


            • #7
              there are many ways of encryption:
              md5() will encrypt a string into 32 characters =click here
              sha1() will encrypt a string into 40 characters using an algorithm click here
              there are more, or i guess if you were really interested you could write your own function to encrypt and decrypt a string

              btw that code posted was i think a flat file login system, you could easily edit it to use mysql
              php & asp tutorials - the birthplace - biorust - photoshop and web technologies

              Comment


              • #8
                well i'v made the form, but i can't yet conecto to the data base (mysql) can you just tell me the next steps? thanks

                Comment


                • #9
                  can anybody help me? thanks

                  Comment


                  • #10
                    to connect to a db

                    put this code:

                    mysql_connect("localhost","username","password");
                    mysql_select_db("dbname");

                    you must edit this according to the username and password and database that your host sets up for you, if it doesnt exist you will get errors.

                    also dw i had trouble connecting to db when i started too, you'll get the hang of it
                    php & asp tutorials - the birthplace - biorust - photoshop and web technologies

                    Comment


                    • #11
                      Hi iv'e created a data base with phpmyadmin and with the form login/register i always get this message:
                      'Registration Failed
                      We're sorry, but an error has occurred and your registration for the username sd, could not be completed.
                      Please try again at a later time.'

                      the code is this:

                      Code:
                      <?
                      session_start(); 
                      include("database.php");
                      
                      /**
                       * Returns true if the username has been taken
                       * by another user, false otherwise.
                       */
                      function usernameTaken($username){
                         global $conn;
                         if(!get_magic_quotes_gpc()){
                            $username = addslashes($username);
                         }
                         $q = "select username from users where username = '$username'";
                         $result = mysql_query($q,$conn);
                         return (mysql_numrows($result) > 0);
                      }
                      
                      /**
                       * Inserts the given (username, password) pair
                       * into the database. Returns true on success,
                       * false otherwise.
                       */
                      function addNewUser($username, $password){
                         global $conn;
                         $q = "INSERT INTO users VALUES ('$username', '$password')";
                         return mysql_query($q,$conn);
                      }
                      
                      /**
                       * Displays the appropriate message to the user
                       * after the registration attempt. It displays a 
                       * success or failure status depending on a
                       * session variable set during registration.
                       */
                      function displayStatus(){
                         $uname = $_SESSION['reguname'];
                         if($_SESSION['regresult']){
                      ?>
                      
                      <h1>Registered!</h1>
                      <p>Thank you <b><? echo $uname; ?></b>, your information has been added to the database, you may now <a href="main.php" title="Login">log in</a>.</p>
                      
                      <?
                         }
                         else{
                      ?>
                      
                      <h1>Registration Failed</h1>
                      <p>We're sorry, but an error has occurred and your registration for the username <b><? echo $uname; ?></b>, could not be completed.<br>
                      Please try again at a later time.</p>
                      
                      <?
                         }
                         unset($_SESSION['reguname']);
                         unset($_SESSION['registered']);
                         unset($_SESSION['regresult']);
                      }
                      
                      if(isset($_SESSION['registered'])){
                      /**
                       * This is the page that will be displayed after the
                       * registration has been attempted.
                       */
                      ?>
                      
                      <html>
                      <title>Registration Page</title>
                      <body>
                      
                      <? displayStatus(); ?>
                      
                      </body>
                      </html>
                      
                      <?
                         return;
                      }
                      
                      /**
                       * Determines whether or not to show to sign-up form
                       * based on whether the form has been submitted, if it
                       * has, check the database for consistency and create
                       * the new account.
                       */
                      if(isset($_POST['subjoin'])){
                         /* Make sure all fields were entered */
                         if(!$_POST['user'] || !$_POST['pass']){
                            die('You didn't fill in a required field.');
                         }
                      
                         /* Spruce up username, check length */
                         $_POST['user'] = trim($_POST['user']);
                         if(strlen($_POST['user']) > 30){
                            die("Sorry, the username is longer than 30 characters, please shorten it.");
                         }
                      
                         /* Check if username is already in use */
                         if(usernameTaken($_POST['user'])){
                            $use = $_POST['user'];
                            die("Sorry, the username: <strong>$use</strong> is already taken, please pick another one.");
                         }
                      
                         /* Add the new account to the database */
                         $md5pass = md5($_POST['pass']);
                         $_SESSION['reguname'] = $_POST['user'];
                         $_SESSION['regresult'] = addNewUser($_POST['user'], $md5pass);
                         $_SESSION['registered'] = true;
                         echo "<meta http-equiv=\"Refresh\" content=\"0;url=$HTTP_SERVER_VARS[PHP_SELF]\">";
                         return;
                      }
                      else{
                      /**
                       * This is the page with the sign-up form, the names
                       * of the input fields are important and should not
                       * be changed.
                       */
                      ?>
                      
                      <html>
                      <title>Registration Page</title>
                      <body>
                      <h1>Register</h1>
                      <form action="<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
                      <table align="left" border="0" cellspacing="0" cellpadding="3">
                      <tr><td>Username:</td><td><input type="text" name="user" maxlength="30"></td></tr>
                      <tr><td>Password:</td><td><input type="password" name="pass" maxlength="30"></td></tr>
                      <tr><td colspan="2" align="right"><input type="submit" name="subjoin" value="Join!"></td></tr>
                      </table>
                      </form>
                      </body>
                      </html>
                      
                      
                      <?
                      }
                      ?>
                      thanks

                      Comment


                      • #12
                        can this error be related to the databese i've created with phpmyadmin?

                        I've take the exemple forum
                        http://www.evolt.org/article/PHP_Log...265/index.html

                        (please don't consider it spam)

                        Comment

                        Working...
                        X