PHP Introductory Tutorial Simple PHP User Login Complete Tutorial

Source: Internet
Author: User
Tags mysql tutorial strlen

<?php
@session_start ();
MySQL tutorial _connect (' localhost ', ' root ', ' 19860427 ') or Die (' database server no exists! ');
mysql_select_db (' wk ') or Die (' Database error! ');
mysql_query ("SET NAMES ' GBK '");//set document CharSet encode
$uid = Get_value (' u ', ' post ');
$login _pwd = get_value (' P ', ' post ');
if (strlen ($uid) <3 | | strlen ($UID) >12) {
Alert (' User length is 3-12 characters! ', ');
}elseif (strlen ($login _pwd) <6 | | strlen ($login _pwd) >12) {
Alert (' Login password is incorrect, length is 6-12 bits ', ');
}else{
$sql = "SELECT * from Wk_member where m_uid= ' $uid ' and m_pass= ' $login _pwd '";
$result = mysql_query ($sql) or Die (Mysql_error ());
if (mysql_num_rows ($result)) {
$rs = Mysql_fetch_array ($result);
if ($rs [' M_pass ']!=md5 ($login _pwd)) {
Alert (' username and password do not match! ', ');
}else{
$_session[' uid ']=array ($rs [' id '], $uid, $rs [' M_tel ']);
Exit ("<script>location= ' registerok.php ';</script>");
}
}else{
Alert (' Login failed, username not present! ', ');
}
}

function Get_value ($st, $str = ' get ')
{
if ($str = = ' Post ')
{
return $_post[$st];
}else{
return $_get[$st];
}
}

?>
<form id= "Form1" Name= "Form1" method= "Post" action= "" >
<label>
<input type= "text" name= "U" id= "U"/>
</label>
User name
<p>
<label>
<input type= "text" Name= "P" id= "P"/>
</label>
Password </p>
<p>
<label>
<input type= "Submit" name= "button" id= "button" value= "submitted"/>
</label>
</p>
</form>

Data table Wk_member Structure
Id
M_uid
M_pass

Original reprint of this site annotated www.111cn.net

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.