Thread: making a nice register script :)

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 making a nice register script :) 
    Unfortunately we’re all human. Except me


    Join Date
    Aug 2011
    Posts
    914
    Thanks given
    528
    Thanks received
    429
    Rep Power
    551
    okay this tutorial will show you how to make a register script


    firsts of all we will need a sql table..

    Code:
    CREATE TABLE IF NOT EXISTS `user` (
      `id` INT(255) NOT NULL AUTO_INCREMENT,
      `name` varchar(32) NOT NULL,
      `password` varchar(255) NOT NULL,
      PRIMARY KEY (`name`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=latin1;
    so we can connect to out sql database we need a config.php..

    Code:
    <?php
        $user_name = "username";
        $password1 = "password";
        $server = "localhost";
        $database = "mysql database name";
        $db_handle = mysql_connect($server, $user_name, $password1);
        $db_found = mysql_select_db($database, $db_handle);
    ?>
    save this as config.php .

    now register.php file

    Code:
    <table width="100%">
    <form method="post" action="create.php">
    <tr>
    <td width="21%"><label for="name">Server Name</label></td>
    <td><input name="name" maxlength="35" /></td>
    </tr>
    <tr>
    <td width="21%"><label for="name">Password</label></td>
    <td><input name="password" maxlength="35" /></td>
    </tr>
    <tr>
    <td><input type="submit" value="submit" /></td>
    </tr>
    </form>
    </table>
    save this as register.php

    next we need create.php that adds info to database

    Code:
    <?php
    
    $name = $_POST['name'];
    if ($name == '') exit ('You must enter a server name'); // checks if you typed username
    $password = $_POST['password'];
    if ($password == '') exit ('You must enter a password'); // checks if you typed username
    include('config.php');
    
    $name = str_replace("<", "&lt;", $name);
    $name = str_replace(">", "&gt;", $name);
    $name = preg_replace("%\n%", "<br>", $name);
    $name = mysql_real_escape_string($name);
    $password = mysql_real_escape_string($password);
    mysql_query("INSERT INTO `user` (`name`,`password`) VALUES ('".$name."','".$password."')") or die(mysql_error());
    echo '<head><meta http-equiv="REFRESH" content="0;url=index.php"></HEAD>'; // refresh after adding user to db
    
    }
    
    ?>
    Reply With Quote  
     

  2. #2  
    Registered Member Spida's Avatar
    Join Date
    Sep 2007
    Age
    24
    Posts
    368
    Thanks given
    13
    Thanks received
    23
    Rep Power
    4
    If you're gonna post a tutorial at least do it right
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Sep 2010
    Posts
    80
    Thanks given
    7
    Thanks received
    3
    Rep Power
    1
    Use PDO.

    And your code looks alright besides that, but it's not very.. tutorial-like. It's just a snippet of copy + pasting stuff. Tell people how it works, not just give them a whole file. Go through and say stuff like:

    Code:
    <form method="post" action="create.php">
    Means that you're posting data (go more in-depth or whatever) and on submit sending the data (and you) to create.php.
    I wrote something witty but it said it was too long, so I just wrote this instead.
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Feb 2012
    Posts
    264
    Thanks given
    88
    Thanks received
    34
    Rep Power
    0
    Thank you, useful.
    Reply With Quote  
     

  5. #5  
    Unfortunately we’re all human. Except me


    Join Date
    Aug 2011
    Posts
    914
    Thanks given
    528
    Thanks received
    429
    Rep Power
    551
    im glad that i helped you
    Reply With Quote  
     

  6. #6  
    Rukin sux

    Sieg's Avatar
    Join Date
    May 2009
    Posts
    1,040
    Thanks given
    223
    Thanks received
    278
    Rep Power
    244
    I'm assuming this is you first registration script? Here's a few things that could be changed:

    • You should just use regular expressions to check if they have any illegal characters within the name variable
    • You should also think about making a better way of outputting errors
    • Leaving the passwords in plain text form is definitely a bad way to do it. Use some salting methods and password hashing functions. I personally recommend sha256 or higher. But I'm sure there's a better way to do it out there
    • Lastly, as Amaranth stated, use PDO.


    I'm sure all of these will be new to you. But I guess it's always a good time to learn.
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  7. #7  
    Registered Member
    Anthony`'s Avatar
    Join Date
    Sep 2008
    Age
    23
    Posts
    770
    Thanks given
    75
    Thanks received
    164
    Rep Power
    204
    Quote Originally Posted by Sub-Zero View Post
    I'm assuming this is you first registration script?
    • Leaving the passwords in plain text form is definitely a bad way to do it. Use some salting methods and password hashing functions. I personally recommend sha256 or higher. But I'm sure there's a better way to do it out there
    Use crypt()'s Blowfish implementation (bcrypt)!
    Reply With Quote  
     

  8. #8  
    anInt69

    Max _'s Avatar
    Join Date
    Feb 2012
    Age
    21
    Posts
    1,824
    Thanks given
    428
    Thanks received
    710
    Rep Power
    599
    Well done, Luke.
    Reply With Quote  
     

  9. #9  
    Registered Member
    Join Date
    Jul 2012
    Posts
    14
    Thanks given
    0
    Thanks received
    1
    Rep Power
    11
    This is already pretty easy if you know how php css and can use mysql. But most people can't so good release.
    Reply With Quote  
     

  10. #10  
    Unfortunately we’re all human. Except me


    Join Date
    Aug 2011
    Posts
    914
    Thanks given
    528
    Thanks received
    429
    Rep Power
    551
    thank you
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Bells login & register script. {Basic}
    By Bells in forum Website Development
    Replies: 21
    Last Post: 10-10-2011, 02:41 PM
  2. [Login/Register] Need a WORKING Login and register script.
    By Tom Sawyer in forum Website Development
    Replies: 4
    Last Post: 09-10-2009, 08:17 AM
  3. 3 In 1 Login Script - Register/Login/Member's Page
    By Purehit in forum Website Development
    Replies: 13
    Last Post: 01-29-2009, 09:20 AM
  4. [PHP]Register Script
    By Harvey in forum Website Development
    Replies: 45
    Last Post: 01-08-2009, 11:52 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •