Ec (2); php user registration and login program & nbsp; functionislogin_xzy () & nbsp ;{& nbsp; & nbsp; if (! Isset ($ _ SESSION [user]) {& nbsp; $ json [status] 1; & nbsp;} else {& nbsp; & nbsp; $ ssess_db (& quot; sess script ec (2); script
Php user registration and login program
Function islogin_xzy ()
{
If (! Isset ($ _ SESSION ['user']) {
$ Json ['status'] = 1;
} Else {
$ Ssess _ = db ("session as s ");
$ Where = "s. session_id = '". Session_id (). "' and u. uid is not null ";
If ($ user = $ ssess _-> join ("'user' as u on u. uid = s. uid ")-> field (" u. *, s. session_id, s. uid ")-> where ($ where)-> find ()){
$ Json ['status'] = 0;
$ Json ['data'] = $ user;
} Else {
$ Json ['status'] = 1;
}
}
Echo json_encode ($ json );
}
Function reg_xzy ()
{
$ User _ = db ("user ");
$ Reg ['email '] = strip_tags ($ _ POST ['email']);
$ Reg ['pass'] = empty ($ _ POST ['pass'])? "": Md5 ($ _ POST ['pass']);
$ Reg ['sex'] =$ _ POST ['sex'] = 'male' | $ _ POST ['sex'] = 'female '? $ _ POST ['sex']: '';
$ Reg ['nickname'] = strip_tags ($ _ POST ['nickname']);
$ Reg ['regip'] = ip2long (getip ());
$ Reg ['regtime'] = time ();
$ I = 0;
Foreach ($ reg as $ v ){
If (! Empty ($ v) $ I ++;
}
If ($ I! = 6 ){
$ Json ['status'] = 1;
$ Json ['info'] = 'Incomplete registration items! ';
} Elseif ($ user _-> where ("'email '=' {$ reg ['email ']}'")-> find ()){
$ Json ['status'] = 1;
$ Json ['info'] = 'registered email address! ';
} Elseif ($ uid = $ user _-> insert ($ reg )){
$ Session _ = db ("session ");
$ Session _-> where ("session_id = '". Session_id (). "'")-> update (array ('uid' => $ uid ));
$ Sessionas _ = db ("session as s ");
$ Where = "s. session_id = '". Session_id (). "' and s. uid is not null ";
If ($ user = $ sessionas _-> join ("user as u on u. uid = s. uid ")-> field (" u. *, s. session_id, s. uid ")-> where ($ where)-> find ()){
$ _ SESSION ['user'] = $ user;
$ Json ['data'] = $ user;
$ Json ['status'] = 0;
} Else {
$ Json ['status'] = 1;
$ Json ['info'] = 'automatic login error. Please log on manually! ';
}
} Else {
$ Json ['status'] = 1;
$ Json ['info'] = 'registration failed! ';
}
Echo json_encode ($ json );
}
Function logout_xzy ()
{
$ Session _ = db ("session ");
$ Session _-> where ("session_id = '". Session_id (). "'")-> update (array ("uid" => null ));
Session_destroy ();
}