PHP login and Set cookie code

Source: Internet
Author: User
Tags set cookie setcookie sprintf trim

Provide a can save the user login information to do, here is a simple PHP login and set the cookie code Oh, very simple.

if (! $c _log) {
$title. = ' landing ';
if ($_server[' Request_method ']== ' POST ') {
if (isset ($_post[' username ')) && trim ($_post[' username '])!= ' && isset ($_post[' password ']) & & Trim ($_post[' password '])!= ') {
$username =trim ($_post[' username '));
$password =enc_p (Trim ($_post[' password '));
$q _author=sprintf (' select * from%s where username=%s and password=%s ', $dbprefix. ' member ', SqlString ($username, ' text ') , SqlString ($password, ' text '));
$author =mysql_query ($q _author) or Die (");
$r _author=mysql_fetch_assoc ($author);
if (mysql_num_rows ($author) >0) {
if ($r _author[' status ']==0 | | $r _main[' veri ']>0) {
$uSQL =sprintf (' update%s set visit=visit+1, visitdate=%s where id=%s ', $dbprefix. ' member ', Time (), $r _author[' id ');
$result =mysql_query ($uSQL) or Die (');
Session_unset ();
Session_Start ();
$_session[' palu_id ']= $r _author[' id '];
if (Isset ($_post[' Remember ')) && $_post[' Remember ']== ' 1 ') {
Setcookie (' Palu_u ', $username, Time () +86400*30);
Setcookie (' palu_p ', $password, Time () +86400*30);
}else{
Setcookie (' Palu_u ', ', ', Time ());
Setcookie (' palu_p ', ', ', Time ());
}
}else{
$e = 1;
}
}else{
$e = 2;
}
Mysql_free_result ($author);
}
if (Isset ($_get[' m ')) $u []= ' m= '. $_get[' m '];
if (isset ($_get[' t ')) $u []= ' t= '. $_get[' t '];
if (Isset ($_get[' page ')) $u []= ' page= '. $_get[' page '];
if (Isset ($e)) $u []= ' e= '. $e;
$topinfo. = ' <script type= ' text/javascript ' >location.href= '. (Isset ($u)? Join (' & ', $u): './'). '; </script> ';
}else{
if (Isset ($_get[' e ')) {
if ($_get[' E ']==2) {
$msg = ' username/password Error! ';
}elseif ($_get[' e ']==3) {
$msg = ' Registration successful! Please '. ($r _main[' Veri ']>0?) Login ': ' Wait for admin audit '. ';
}else{
$msg = ' Your account has not yet passed the audit, please try again later. ';
}
}
   $content. = ' <div class= ' tcontent ' > '. (Isset ($msg)? ' <div class= "Msg_v" > '. $msg. ' </div> ': '). ' <div class= "title" > Login </div><div class= "lcontent" ><form method= "post" action= "onsubmit=" return Chklog (); " ><div class= "formline" ><label for= "FormName" > Username: </label><input name= "username" FormName "size=" maxlength= "/></div><div class=" formline "><label for=" FORMPW "> Password: </ Label><input name= "Password" id= "FORMPW" "size=" maxlength= "type=" password class= "Formline" ><label></label><input name= "Remember" value= "1" type= "checkbox" title= "to ensure information security , please do not choose this item in the Internet Café or public computer room! If you want to cancel this option in the future, simply click "Exit Login". "/> Remember me </div><div class=" formline "><input type=" Submit "value=" Landing "id=" Formsubmit "class=" button "/ > <input type= "reset" value= "Cancel" class= button "/><br/>". ($r _main[' Openreg ']==0?) <a href= "? M=reg" > Join the Class </a> | ':'').' &Lt;a href= "? m=lostpw" > Forget password </a></div></form></div></div> ';
}
}else{
$topinfo. = ' <script type= ' text/javascript ' >location.href= './';</script> ';
}
?>

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.