国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 PHP開發(fā) ThinkPHP user registration login message complete example

ThinkPHP user registration login message complete example

Dec 21, 2016 pm 04:35 PM
thinkphp

This article describes the functions implemented by ThinkPHP in the form of examples, including user registration, login, and leaving messages. What you need to pay attention to here is that when instantiating a user class when there is a user model, use the D method to implement it.

UserActivion.class.php page:

<?php
class UserAction extends Action{
public function add(){
$user = D("user");
$user->create();
$result = $user->add();
if($result){
$this->assign("jumpUrl","__APP__/index/index");
$this->success(&#39;注冊成功!&#39;);
}else{
//echo $user->getError();
$this->assign("jumpUrl","__APP__/user/register");
$this->error($user->getError());
}
}
public function register(){
$this->display();
}
public function login(){
$this->display();
}
public function checklogin(){
$username = $_POST[&#39;username&#39;];
$passwd = $_POST[&#39;passwd&#39;];
$user = D("user");
//$User->where(&#39;id=8&#39;)->find();這里的where 語句要注意一下,如果是其他字段的話后面一定要有單引號
$userinfo = $user->where("username =&#39;$username&#39;")->find();
if(!empty($userinfo)){
if($userinfo[&#39;passwd&#39;] == $passwd){
Cookie::set(&#39;userid&#39;,$userinfo[&#39;id&#39;],time()+3600*24);
Cookie::set(&#39;username&#39;,$username,time()+3600*24);
Cookie::set(&#39;lastlogintime&#39;,time(),time()+3600*24);
$this->assign("jumpUrl","__APP__/index/index");
$this->success(&#39;登陸成功!&#39;);
}else{
$this->assign("jumpUrl","__APP__/user/login");
$this->error(&#39;密碼出錯,請重新輸入!&#39;);
}
}else{
$this->assign("jumpUrl","__APP__/user/login");
$this->error(&#39;用戶名不存在!&#39;);
}
}
public function loginout(){
Cookie::delete(&#39;username&#39;);
Cookie::delete(&#39;lastlogintime&#39;);
$this->assign("jumpUrl","__APP__/index/index");
$this->success(&#39;您已經(jīng)成功退出,歡迎您的下次登錄!&#39;);
}
}

IndexAction.class.php page:

<?php
// 本類由系統(tǒng)自動生成,僅供測試用途
class IndexAction extends Action{
public function insert() {   
$content = new ContentModel();
$result = $content->create();
if(!$result){
$this->assign("jumpUrl","__URL__/index");
$this->error($content->getError());//如果創(chuàng)建失敗,表示驗證沒有通過,輸出錯誤信息
}else{//驗證通過,進行其他操作
$content->userid=Cookie::get(&#39;userid&#39;);
$content->add();
$this->assign("jumpUrl","__URL__/index");
$this->success(&#39;添加成功!&#39;);
}
} 
// 數(shù)據(jù)查詢操作  
public function index() {
$content = new ContentModel();
$list = $content->findAll();  
//用戶的cookie
$username = Cookie::get(&#39;username&#39;);
$lastlogintime = Cookie::get(&#39;lastlogintime&#39;);
$this->assign(&#39;list&#39;,$list);    
$this->assign(&#39;title&#39;,&#39;我的首頁&#39;);
$this->assign(&#39;username&#39;,$username);
$this->assign(&#39;lastlogintime&#39;,$lastlogintime);
$this->display();  
} 
// 刪除操作
public function delete(){
$content = new ContentModel();
$id = $_GET[&#39;id&#39;];
if($content->where("id=$id")->delete()){
$this->assign("jumpUrl","__URL__/index");
$this->success(&#39;刪除成功!&#39;);
}else{
$this->assign("jumpUrl","__URL__/index");
$this->error(&#39;刪除失??!&#39;);
}
} 
// 編輯操作
public function edit(){
$content = new ContentModel();
$id = $_GET[&#39;id&#39;];
if($id != &#39;&#39;)
{
//$data = $content->select($id);
$data = $content->where("id=$id")->select();
if(!empty($data)){
$this->assign(&#39;data&#39;,$data);
}else{
echo "數(shù)據(jù)為空!";
}
}
$this->assign(&#39;title&#39;,&#39;編輯頁面&#39;);
$this->display();
}
// 更新操作
public function update(){
$content = new ContentModel();
//直接使用create(),自動會幫你進行數(shù)據(jù)的傳值
/*$content->create();
$content->save(); // 根據(jù)條件保存修改的數(shù)據(jù)
echo "更新數(shù)據(jù)成功!";*/
// 使用post 傳值過來,進行更新
$id = $_POST[&#39;id&#39;];
if($id != &#39;&#39;)
{
$data[&#39;id&#39;] = $id;
$data[&#39;title&#39;] = $_POST[&#39;title&#39;];
$data[&#39;content&#39;] = $_POST[&#39;content&#39;];
if($content->save($data))// 根據(jù)條件保存修改的數(shù)據(jù)
{
$this->assign("jumpUrl","__URL__/index");
$this->success(&#39;更新數(shù)據(jù)成功!&#39;);
}
else{
$this->assign("jumpUrl","__URL__/index");
$this->success(&#39;更新數(shù)據(jù)失?。?amp;#39;);
}
}else
{
echo "保存數(shù)據(jù)失??!";
}
}
}
?>

ContentModel.class.php page:

<?php
class ContentModel extends Model{
/*
* 自動驗證
* array(驗證字段,驗證規(guī)則,錯誤提示,驗證條件,附加規(guī)則,驗證時間)
*/
protected $_validate = array(
array(&#39;title&#39;,&#39;require&#39;,&#39;標題必須填寫!&#39;),
array(&#39;content&#39;,&#39;require&#39;,&#39;內(nèi)容必須填寫!&#39;), 
);
/* 
* 自動填充
* array(填充字段,填充內(nèi)容,填充條件,附加規(guī)則)
*/
protected $_auto = array(
array(&#39;addtime&#39;,&#39;time&#39;,1,&#39;function&#39;),
);
}
?>

UserModel.class.php page:

<?php
class UserModel extends Model{
protected $_validate = array(
array(&#39;username&#39;,&#39;&#39;,&#39;帳號名稱已經(jīng)存在!&#39;,0,&#39;unique&#39;,1), 
);  
}
?>

It should be noted here that using automatic When verifying, you must use $user = D("user") instead of $user = M("user"). Using the M method will report an error. The D function is used to instantiate the Model, and the M function is used to instantiate the user instance. to a file without a model.

success.html page:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="refresh" content="20; url=&#39;{$jumpUrl}&#39;" />
<title>信息提示</title>
</head>
<body>
<div id="man_zone">
<table width="40%" border="1" align="center" cellpadding="3" cellspacing="0" class="table" style="margin-top:100px;">
<tr>
<th align="center" style="background:#cef">信息提示</th>
</tr>
<tr>
<td><p>{$message}<br />
2秒后返回指定頁面!<br />
如果瀏覽器無法跳轉(zhuǎn),<a href="{$jumpUrl}" rel="external nofollow" >請點擊此處</a>。</p></td>
</tr>
</table>
</div>
</body>
</html>


For more complete examples of ThinkPHP user registration, login and message related articles, please pay attention to the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1502
276
How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

How is the performance of thinkphp? How is the performance of thinkphp? Apr 09, 2024 pm 05:24 PM

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.

Development suggestions: How to use the ThinkPHP framework for API development Development suggestions: How to use the ThinkPHP framework for API development Nov 22, 2023 pm 05:18 PM

Development suggestions: How to use the ThinkPHP framework for API development. With the continuous development of the Internet, the importance of API (Application Programming Interface) has become increasingly prominent. API is a bridge for communication between different applications. It can realize data sharing, function calling and other operations, and provides developers with a relatively simple and fast development method. As an excellent PHP development framework, the ThinkPHP framework is efficient, scalable and easy to use.

Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Development suggestions: How to use the ThinkPHP framework to implement asynchronous tasks Nov 22, 2023 pm 12:01 PM

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

See all articles