thinkphp5 の最も完璧な登録とログイン

爆肝混世大魔王-流笙 第五人格服务
リリース: 2021-03-15 09:02:15
オリジナル
144 人が閲覧しました

名前空間アプリインデックスコントローラー;

アプリ共通コントローラーBase; //共通コントローラーをインポート

use think Db;

useアプリインデックスモデル Add as AddModel;

use think Validate;

use think セッション;

use think facade URL;

class Index extends Base {

public

function Index() {

$s = cookie( 'email' );

if ( is_null( $s ) ) {

return $this->fetch();

} else {

$q = 'ユーザー名とメールアドレスは';

$h = 'おかえり';

$this->assign ( [ 'メール' => $s,

'q' => $q,

'h' => $h,

] );

return $this->fetch( 'user / dlhdym' );

}

}

}

名前空間アプリインデックスコントローラー;

thinkコントローラーを使用;

アプリ共通検証を使用;

アプリ共通コントローラーBaseを使用;

アプリを使用共通モデル User as UserModel;

class User extends Base {

//登録ページ

public

function register() {

$this->assign( [ 'title' => 'ユーザー登録' ] );

return $this->fetch();

}

public

function insert() {

//データを受け入れる

$data = input( 'post.' );

$ c = $_POST[ 'メール' ];

$d = $_POST[ 'モバイル' ];

$code = $_POST[ 'コード' ];

$c = UserModel::get( [ 'メール' = > $_POST[ 'email' ] ] );

$d = UserModel::get( [ 'mobile' => $_POST[ 'mobile' ] ] );

$h = is_null( $c ) ;

$z = is_null( $d );

if ( $h + $z != 2 ) {

echo "<script>alert('こんにちは、登録したいメールアドレスまたは携帯電話番号を入力してくださいプラットフォーム 誰かがすでに登録しています。情報を変更してください');</script>";

return $this->fetch( 'user/register' );

}

if ( !captcha_check( $code ) ) {

echo "<script>alert('確認コードが入力されていないか、確認コードが間違っています!');</script>";

return $this->fetch( 'user /register' );

}

$sjh = $_POST[ 'mobile' ];

if ( preg_match( "/^1[34578]{1}d{9}$/", $sjh ) ) { } else {

echo "<script>alert('携帯電話番号ではありません!');</script>";

return $this->fetch( 'user/register' );

exit ;

}

/ /バリデーターをインスタンス化します

$validate = new app common validate User;

//データ検証を実行します

if ( $validate->check( $data ) ) {

$data = input( 'post.' );

unset( $data[ 'password_confirm' ] );

$user = new UserModel( $data );

$a = $user->allowField( [ 'name', 'メールアドレス', 'モバイル', 'パスワード' ] )->save();

if ( $a = 1 ) {

$code = input( 'code' );

echo "<script> alert('登録が成功しました。ログインしてご覧ください!');</script>";

return $this->fetch( 'user/login' );

}

} else {

dump( $validate->getError () );

}

return $this->fetch( 'user/register' );

}

//ユーザーログイン

public

function login() {

$this-> assign( [ 'title' => 'ユーザー ログイン' ] );

return $this->fetch( 'user/login' );

}

public

関数loginCheck() {

if ( isset( $_POST[ 'email' ] ) ) {} else {

echo "<script>alert('アドレスバーを動かさないでください!');</script&gt ;";</p><p> return $this-> redirect( 'index/index/index' );</p> <p> exit;</p> <p> }</p> <p> $a = UserModel::get( [ 'email' => $_POST[ 'メール' ] ] );</p> <p> $b = UserModel::get( [ 'パスワード' => $_POST[ 'パスワード' ] ] );</p> <p> $c = $_POST[ 'メール' ];</p> <p> $d = $_POST[ 'パスワード' ];</p> <p> $e = is_null( $a );</p> <p> $f = is_null( $b );</p> <p> if ( $c != '' && $d != '' ) { </p> <p> if ( $f + $e != 1) {</p> <p> cookie( 'email', $c, 900000 ); // Cookie の保存時間を指定 </p> <p> $s = cookie( 'email' );</p> <p> if ( $s = cookie( 'email' ) ) { </p> <p> $q = 'ユーザー名とメールアドレスは';</p> <p> $h = 'おかえり';</p> <p> echo "<script>alert('ログインしました! ');</script>";

$this->assign( [ 'email' => $c,

'q' => $q,

'h' => $h ,

] );

return $ this->fetch( 'user/dlhdym' );

}

} else {

echo "<script>alert('邮箱或密码错误');</script>";

return $this->fetch( 'user/login' );

}

} else {

echo "<script>alert('您还没有输入邮箱或密码');</script>";

return $this->fetch( 'user/login' );

}

}

}

namespace app\ index\ controller;

use think\ Controller;

use think\ facade\ Url;

use think\ Cookie;

class tt extends Controller {

public

function index() {

cookie::delete( 'email' );

return $this->fetch( 'index/index' );

}

}

 

 

   

 

 {include file="public:header"/}

  {include file="index:nav"/}

 

 

{include file="public:right"/}

{include file="public:footer"/}

 {include file="public:header"/}

  {include file="public:nav"/}

 

 

{include file="public:right"/}

{include file="public:footer"/}

 {include file="public:header"/}

  {include file="public:nav"/}

 

 

{include file="public:right"/}

{include file="public:footer"/}



  验证码:

 

{$title|default="首页"}

 

   

 

   

 

 

 

   

以上がthinkphp5 の最も完璧な登録とログインの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

関連ラベル:
1
ソース:php.cn
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
最新の問題
人気のチュートリアル
詳細>
最新のダウンロード
詳細>
ウェブエフェクト
公式サイト
サイト素材
フロントエンドテンプレート
私たちについて 免責事項 Sitemap
PHP中国語ウェブサイト:福祉オンライン PHP トレーニング,PHP 学習者の迅速な成長を支援します!