Wednesday, 15 May 2013

Simple but secure user registration with PHP and mysqli -



Simple but secure user registration with PHP and mysqli -

it's bit hard understand, extract , apply advice provided advanced users posts this or this , others, non-advanced users me.

i need simple secure mysqli , php user registration (username + password); i've tried follow advices contained in these post, i'm not sure if code secure injections , if outdated:

registration.php:

$host = "localhost"; $dbuser = "xxxx"; $dbpassword = "xxxx"; $dbname = "xxxx"; $conn = mysql_connect($host, $dbuser, $dbpassword); if($conn == 0){ echo "connection failed"; } $db_select = mysqli_select_db($dbname, $conn); $username = mysqli_real_escape_string($_post['username']); $password = $post['password']; if($user == '' or $password == ''){ echo "compile all!"; }else{ $query = "insert 'user' ('username' , 'password') values ('$username' , '$password')"; $query2 = mysqli_query($query); echo "registration complete"; }

it needs lot of improvements, hope understand advices because i'm new this.

you need remain consistent functions, mysql_* functions not interchangeable mysqli_* functions. stick mysqli_* functions , read prepared statements, help preventing injection.

as far passwords, first thing need know not store passwords in database. means plain text. if have access php5.5 +, read these functions straight relate hashing password, can store in database.

php mysqli user-registration

No comments:

Post a Comment