PHP获取客户端真实IP

按顺序依次判断$_SERVER['HTTP_X_FORWARDED_FOR']、$_SERVER['HTTP_CLIENT_IP']、$_SERVER['REMOTE_ADDR']这三个变量,如果有值就马上返回。翻开PHP手册,查看$_SERVER数组的解释,你会发现,手册里居然没有HTTP_X_FORWARDED_FOR、HTTP_CLIENT_IP这两个元素,只有REMOTE_ADDR的解释。首先,$_SERVER数组以HTTP_开头的元素,是来自客户端的header头信息,也就是说,它们是客户端传给服务器的。因此,这些值是可以伪造的,是不安全的!但是,这并不代表它们就没有用处。

分类至 PHP
0条评论

MySQL5.7重置root密码

本人由于root密码设置太复杂,距离买云服务器过去好长时间,记不起来了,只好重置密码。

编辑配置文件/etc/my.cnf,在 [mysqld] 段加入一行:skip-grant-tables

如下:

[mysqld]
skip-grant-tables
skip-ssl
port = 3306
......

执行重启指令:service mysqld restart

[root@centos ~]# service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL... SUCCESS! 

重启成功后,即可免密码登录root用户:mysql -u root

[root@centos ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

登录成功后,执行SQL更改root密码(假设为123456):

UPDATE mysql.user SET authentication_string = PASSWORD('123456') WHERE User = 'root';

mysql> UPDATE mysql.user SET authentication_string = PASSWORD('123456') WHERE User = 'root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> 

注意上面的SQL语句,在5.7版本后,原来的密码字段名称Password改成了authentication_string。

退出mysql控制台,把添加到/etc/my.cnf配置文件的 skip-grant-tables 这行删除,再重启服务:service mysqld restart。之后,我们就可以使用新密码登录了。

[root@centos ~]# service mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL.. SUCCESS! 
[root@centos ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

分类至 MySQL
1条评论

CentOS mail配置163邮箱

0、本文演示环境:本文实际操作的系统是 CentOS 7.6,为腾讯云服务器。
1、获取163邮箱授权码:为了安全,我们不应直接使用原始密码登录第三方客户端,因此有了授权码这个东西。授权码是用于登录第三方邮件客户端的专用密码。登录163邮箱后,进入设置--客户端授权密码--设置客户端授权码,开启并设置授权码(且要开通SMTP服务)
2、在Linux系统上安装mailx服务:在命令行直接输入mail指令,如果提示找不到该指令,则表示你还没有安装该服务,请使用yum安装该服务。
3、添加163邮箱的smtp配置:在系统文件 /etc/mail.rc 末尾追加下面内容(按实际情况修改成你的账号和授权码)
4、下载163邮箱的证书:上述配置开启了SSL安全连接,因此我们还需要手动获取163邮箱的SSL证书保存到本地 /root/.certs 目录,以备调用和验证。

分类至 Linux
0条评论