Register and login with links within the database

Source: Internet
Author: User
Tags sql injection

Registering and logging in is actually extracting and writing data from a table

1. (1) First set up a registration page

1<body>23<form action="chuli.php"Method="Post">4<div> User name: <input type="text"Name="ID"/></div>5<div> Password: <input type="text"Name="pwd"/></div>6<div> Name: <input type="text"Name="name"/></div>7<div>Gender:8Male <input type="Radio"Name="Sex"Value="1"/>9Female <input type="Radio"Name="Sex"Value="0"/>Ten</div> One<di><input type="Submit"Value="Register"/></div> A</form> -</body>

(2) Create a Registration processing page (also write data to a table in the database)

1<?PHP23 4 //1. Take the submitted data5$id =$_post["ID"];6$pwd =$_post["pwd"];7$name =$_post["name"];8$sex =$_post["Sex"];9 //2. Write to the database;Ten$db =NewMysqli ("localhost","Root","123456","text_0408"); One$sql ="INSERT INTO Zhuce AValue'{$id}','{$pwd}','{$name}','{$sex}')"; - //$result = $db->query ($sql); - if($dbquery ($sql)) the { -Echo"Registration Successful"; - } - Else{ +      -Echo"Registration Failed"; +     } A?>

2. Login and register almost,

(1) Create landing page

1<body>23<form action="dengluchuli.php"Method="Post">4<div> User name: <input type="text"Name="ID"/></div>5<div> Password: <input type="text"Name="pwd"/></div>6<div><input type="Submit"Value="Login"/></div>7 8</form>9</body>

(2) Landing processing page (extracting data from a table)

1<?PHP2$id =$_post["ID"];3$pwd =$_post["pwd"];4$db =NewMysqli ("localhost","Root","123456","text_0408");5$sql ="select pwd from zhuce where id= ' {$id} '";6$result = $dbquery ($sql);7$arr = $resultFetch_row ();8 if($arr [0]== $pwd &&!empty ($pwd))9 {TenEcho"Login Successful"; One } A Else{ -Echo"Logon Failure"; -      the}

SQL injection attacks
1. Filter the user's input
2. Using Preprocessing statements
3. When writing code, try to avoid

Register and login with links within the database

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.