Install ThinkPHP in Tencent Cloud

Tencent Cloud and Baota Panel

Exchange blogroll: laker.me
Github:https://github.com/younglaker

Installation

Install ThinkPHP 5 in Baota Panel:

ThinkPHP

Choose ThinkPHP

ThinkPHP

Add your server infomation:

server infomation

Finish installation

Finish

You can visit your website now:

visit

You can edit the welcome message:

edit

Create a database table

Manage your database:

database

Enter phpMyadmin:

phpMyadmin

Create a user table:

user table

Insert a data for admin user:

  • name: admin
  • pwd: 21232f297a57a5a743894a0e4a801c3 (admin)

Create a login page

Connect ThinkPHP to database:

Connect

Edit config file for debug pattern:

config

Add a view file:

view

application/index/view/login/index.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login system</title>
<link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="gray-bg">
<div class="container">
<div class="row">
<div class="col-sm-7">
<div class="ibox float-e-margins">
<div class="ibox-content">
<div class="row">
<div class="col-sm-6 b-r">
<h3 class="m-t-none m-b">Login</h3>
<p>Welcome (⊙o⊙)</p>
<form role="form" action="{:url('login/dologin')}" method="post">
<div class="form-group">
<label>Useranme</label>
<input type="text" placeholder="Input your name" class="form-control" name="user_name">
</div>
<div class="form-group">
<label>Password</label>
<input type="password" placeholder="Input your password" class="form-control" name="user_pwd">
</div>
<div>
<button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit"><strong>Login</strong>
</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="/static/js/jquery.min.js?v=2.1.4"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>

Add controller Login:
application/index/controller/Login.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace app\index\controller;
use think\Controller;
class Login extends Controller
{
public function index()
{
// Deal with login
return $this->fetch();
}
public function doLogin()
{
$param = input('post.');
if(empty($param['user_name'])){
$this->error('Username can't be null');
}
if(empty($param['user_pwd'])){
$this->error('Password can't be null');
}
// Check username
$has = db('users')->where('user_name', $param['user_name'])->find();
if(empty($has)){
$this->error('Usename or password is wrong');
}
// Check password
if($has['user_pwd'] != md5($param['user_pwd'])){
$this->error('Usename or password is wrong');
}
// Remember the user infomation
cookie('user_id', $has['id'], 3600); // One month's validity period
cookie('user_name', $has['user_name'], 3600);
$this->redirect(url('index/index'));
}
}

Visit:

Success


Install ThinkPHP in Tencent Cloud

本文原创自http://laker.me/blog,转载请注明出处,欢迎交换友链

如果本文对您有帮助,微信扫一扫,请我吃个鸡腿吧

评论组件不稳定,有事请联系V信 lakerHQ (请备注来自博客)