Username:
Password:
Remember me:
Register

Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)


Search forums via Google


1 Users appreciate this thread.

A sample register script (UPDATED)
Started by ryanb000977
(2014-05-12 19:48:16)
ryanb000977 (2014-05-12 19:48:16)
Hello, this tutorial is a more updated and effective register script.

Step 1
Create a table in your databse named, "users" and have at least the columns below:

Column 1:
- Name: id
- Type: int
- Length: 5

Column 2:
- Name: username
- Type: char
- Length: 15

Column 3:
- Name: password
- Type: text
- Length: NULL

Column 4:
- Name: ip
- Type: char
- Length: 16

Step 2
Create the PHP code beolow:

Source Code
<?php session_start(); $logged = $_SESSION['username']; if(!empty($logged)) { header('Location: index.php'); } $con = mysqli_connect("host","user","pass","db" ); $username = $_POST['username']; $username = mysqli_real_escape_string($con, $username); $username = strip_tags($username); $username = str_replace(' ','',$username); $password = $_POST['password']; $password = mysqli_real_escape_string($con, $password); $password = htmlspecialchars($password, ENT_QUOTES); $password = hash('sha256',$password); $ip = $_SERVER['REMOTE_ADDR']; $select = mysqli_query($con, "SELECT * FROM users WHERE username='$username'" ); $count = mysqli_num_rows($select); if($username !== '' && $password !== '') { $insert = mysqli_query($con, "INSERT INTO users (username, password, ip) VALUES ('$username','$password','$ip')" ); $msg = "You are registsred as " . $username . ". Please <a href=\"login.php\">Login</a>."; $form = 0; } elseif($count === 1) { $msg = "Someone is using that username!"; $form = 1; } else { $msg = "Please make sure all fields are filled in!"; $form = 1; } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Register</title> <style type="text/css"> body { background-color: red; } #main { background-color: white; border: 2px solid black; text-align: center; } </style> </head> <body> <div id="main"> <center> <h1>Register</h1> <?php if($msg !== '') { echo("<p>" . $msg . "</p>" ); } if($form === 1) { echo("<form method=\"post\" action=\"register.php\"> <table> <tbody> <tr> <td>Username:</td> <td><input name=\"username\" type=\"text\" value=\"\"></td> </tr> <td>Password:</td> <td><input name=\"password\" type=\"password\" value=\"\"></td> </tr> <td></td> <td><input name=\"submit\" type=\"submit\" value=\"Register\"></td> </tr> </tbody> </table> </form>" ); } ?> </center> </body> </html>


If there are errors, tell me.

A version in OOP will be posted soon!


This post has been edited one or more times, the last time was:
2014-05-14 02:47:55

angelrulez7 (2014-05-12 21:13:59)
I suggest you salt it by doing this:
hash("sha256", $password.$variable);
a
ryanb000977 (2014-05-12 23:12:31)
@mega Sure

This post has been edited one or more times, the last time was:
2014-05-13 07:01:36

MarioErmando (2014-05-15 12:12:13)
srsly mega


By the way, instead of changing the variable every time, why not mix the functions together?
TheAlexRider (2014-05-28 21:19:19)
I code using Microsoft Visual Web 2013 and upload with FileZilla(Its so good!) What do you? @ryanb000977
joemckellar20 (2014-06-21 16:42:48)
that code don't work
TheAlexRider (2014-07-02 21:00:59)
^... You need to know a bit about SQL First. It worked for me, Ijust don't use it.
joemckellar20 (2014-08-08 00:01:59)
thank
TwilightWinter (2014-09-25 15:27:56)
You used, ( "" ) after echo, it is an error. After curly brackets just type the form HTML.

This post has been edited one or more times, the last time was:
2014-09-25 15:28:20

‚úč
joemckellar20 (2014-11-14 05:18:12)
it gave my pc ebola
qwp789 (2015-06-02 02:45:07)
I'll never forget the day that I connected to retarded MySQL for the first time. .-.
CoolApps (2015-06-20 13:06:17)
such "bump" on a sticky.
The code posted is vulnerable to XSS. Don't use strip_tags(), kids.
Newer account: NodePoint
 

Log in to submit a comment

This topic's ID: 69734

Back to forum: Web Programming (HTML, JS, CSS, PHP, MySQL)


Total registered users: 7674
New registered users today: 0
Newest registered user: Pootpott

©  Copyright 2018 3DSPlaza. All Rights Reserved