Nginx 运行 PHP 显示 “No input file specified” 错误的解决方法

Nginx 环境下使用浏览器访问任何 PHP 文件均显示 No input file specified 而访问 html 文件显示正常

默认安装的 Nginx配置文件中定义 fastcgi 处是:fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

可以将它改成:

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

参考链接:https://blog.csdn.net/yuanyuan_186/article/details/51259078

PHP 根据 IP 地址获取其地理位置(国家,省份,城市等)的方法

<?php
//根据IP地址获取其地理位置(国家,省份,城市等)的方法
function GetIpLookup($ip = ''){  
  if(empty($ip)){  
    return '请输入IP地址'; 
  }  
  $res = @file_get_contents('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=' . $ip);  
  if(empty($res)){
    return false;
  }  
  $jsonMatches = array();  
  preg_match('#\{.+?\}#', $res, $jsonMatches);  
  if(!isset($jsonMatches[0])){
    return false;
  }  
  $json = json_decode($jsonMatches[0], true);  
  if(isset($json['ret']) && $json['ret'] == 1){  
    $json['ip'] = $ip;  
    unset($json['ret']);  
  }else{  
    return false;  
  }  
  return $json;  
} 

$ipInfos = GetIpLookup('192.30.253.112'); //测试 github.com 的IP地址

echo '<pre>';
print_r($ipInfos); 
echo '</pre>';

 

PHP 超全局变量 $_SERVER 获取当前域名 HTTP_HOST 和 SERVER_NAME 的问题

PHP 获取当前域名有两个变量 HTTP_HOST 和 SERVER_NAME:

相同点:

当满足以下三个条件时,两者会输出相同信息。
1. 服务器为 80 端口
2. apache 的 conf 中 ServerName 设置正确
3. HTTP/1.1 协议规范

不同点:

1. 通常情况:
$_SERVER["HTTP_HOST"] 在 HTTP/1.1 协议规范下,会根据客户端的 HTTP 请求输出信息。
$_SERVER["SERVER_NAME"] 默认情况下直接输出 apache 的配置文件 httpd.conf 中的 ServerName 值。

2. 当服务器为非 80 端口时:
$_SERVER["HTTP_HOST"] 会输出端口号,例如:guofeng.io:8080
$_SERVER["SERVER_NAME"] 会直接输出 ServerName 值
因此在这种情况下,可以理解为:HTTP_HOST = SERVER_NAME : SERVER_PORT

3. 当配置文件 httpd.conf 中的 ServerName 与 HTTP/1.0 请求的域名不一致时:
httpd.conf 配置如下:

<virtualhost *>
    ServerName mimiz.cn
    ServerAlias blog.liuguofeng.com
</virtualhost>

客户端访问域名 blog.liuguofeng.com

$_SERVER["HTTP_HOST"] 输出 blog.liuguofeng.com
$_SERVER["SERVER_NAME"] 输出 guofeng.io

所以,在实际程序中,应尽量使用 $_SERVER["HTTP_HOST"] ,比较可靠。

另:

"PHP_SELF"
当前正在执行脚本的文件名,与 document root 相关。举例来说,在 URL 地址为 https://blog.liuguofeng.com/wp-admin/post-new.php 的脚本中使用 $_SERVER['PHP_SELF'] 将会得到 /wp-admin/post-new.php 这个结果。__FILE__ 常量包含当前(例如包含)文件的绝对路径和文件名。

"SCRIPT_NAME"
包含当前脚本的路径。这在页面需要指向自己时非常有用。__FILE__ 包含当前文件的绝对路径和文件名(例如包含文件)。

关于 PHP 中的 逻辑运算 “并且 &&”、”或者 ||”,赋值运算 “=”,布尔返回值,运算符优先级的一些问题

研究代码时发现个有意思的现象

逻辑运算符中的 "并且 &&" 和 "或者 ||"

当 && 前为 false 时,无需执行后面语句即可返回结果 false;

当 && 前为 true 时,需执行后面,若后面为 true 则结果返回 true,若后面为 false 则结果返回 false;

当 || 前为 true 时,无需执行后面语句即刻返回结果 true;

当 || 前为 false 时,需执行后面,若后面为 true 则结果返回 true,若后面为 false 则结果返回 false;

由于逻辑运算符 && ||  的优先级高于赋值运算符 =

以 $b=0 || $c=2 为例

|| 的优先级高一些,先算 0 || $c

由于 $c = 2,所以 即 0 || 2

返回 true,true 就赋给了$b

所 $b = true

echo $b 就等于 1

百度熊掌号 WordPress 插件 保存提示 appid 或 token 错误解决方法

百度熊掌号 WordPress 插件(BaiduXZH Submit) 保存提示 appid 或 token 错误

原因在于插件源码中 save_verify 函数对 home_url() 判断不足,即:

若百度熊掌号绑定的网站地址为 blog.liuguofeng.com,但在 WordPress 后台设定网站主页为 guofeng.io,则会判断不通过,返回失败。

解决方法:

1: WordPress 后台将主页地址修改,由 guofeng.io 修改成 blog.liuguofeng.com

2: 插件源码中(插件地址:/wp-content/plugins/i3geek-baiduxzh),i3geek_baiduXZH_function.php 文件的 save_verify 函数中 home_url() 修改成 https://blog.liuguofeng.com

home_url() 文档解释:

 

记一次阿里云 ECS 服务器数据盘无损扩容

原数据盘 20G 扩容至 25G,购买后通过 SSH 登陆实例进行操作;

操作步骤完全参考阿里云帮助即可:https://help.aliyun.com/document_detail/25452.html

[root@iZ2ze4knyxhkgpnbo7brn7Z ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        40G   15G   23G  39% /
tmpfs           939M     0  939M   0% /dev/shm
/dev/vdb1        20G   13G  6.7G  65% /home/wwwroot
[root@iZ2ze4knyxhkgpnbo7brn7Z ~]# umount /dev/vdb1
[root@iZ2ze4knyxhkgpnbo7brn7Z ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        40G   15G   23G  39% /
tmpfs           939M     0  939M   0% /dev/shm
[root@iZ2ze4knyxhkgpnbo7brn7Z ~]# fdisk -l

Disk /dev/vda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00020f03

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           1        5222    41940992   83  Linux

Disk /dev/vdb: 26.8 GB, 26843545600 bytes
16 heads, 63 sectors/track, 52012 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x78d92770

   Device Boot      Start         End      Blocks   Id  System
/dev/vdb1               1       41610    20971408+  83  Linux
[root@iZ2ze4knyxhkgpnbo7brn7Z ~]# fdisk /dev/vdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): d
Selected partition 1

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-52012, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-52012, default 52012): 
Using default value 52012

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@iZ2ze4knyxhkgpnbo7brn7Z ~]# e2fsck -f /dev/vdb1
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vdb1: 95741/1310720 files (0.8% non-contiguous), 3228283/5242852 blocks
[root@iZ2ze4knyxhkgpnbo7brn7Z ~]# resize2fs /dev/vdb1
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vdb1 to 6553504 (4k) blocks.
The filesystem on /dev/vdb1 is now 6553504 blocks long.

[root@iZ2ze4knyxhkgpnbo7brn7Z ~]# mount /dev/vdb1 /home/wwwroot
[root@iZ2ze4knyxhkgpnbo7brn7Z ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        40G   15G   23G  39% /
tmpfs           939M     0  939M   0% /dev/shm
/dev/vdb1        25G   13G   12G  52% /home/wwwroot

值得注意的点是 fdisk 命令操作时, 是使用 fdisk /dev/vdb 而不是 fdisk /dev/vdb1,这里没仔细看坑了我好长时间,一直扩容失败;

扩容成功。

解决 Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ 错误

安装完 MySQL ,进行运行测试,报 Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ 错误,

[root@localhost mysql]# /usr/local/mysql/bin/mysqld_safe
131206 22:42:51 mysqld_safe Logging to ‘/var/log/mysqld.log’.
131206 22:42:51 mysqld_safe Starting mysqld daemon with databases from /data/mysql/data
131206 22:42:57 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
[root@localhost mysql]# /usr/local/mysql/bin/mysql
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

检查一下 MySQL 的运行状态

[root@localhost mysql]# ps -ef | grep mysql
root     32092  2108  0 22:43 pts/0    00:00:00 grep mysql

查看 /tmp 文件夹的确没有 mysql.sock 文件,

通过 find 命令查找

[root@localhost /]# find / -name mysql.sock
/var/lib/mysql/mysql.sock

原来安装到 /var/lib/mysql/mysql.sock 这个位置啦,我们需要修改 my.cnf 文件

[root@localhost /]# vi /usr/local/mysql/my.cnf

[client]
character-set-server = utf8
port    = 3306
socket  = /var/lib/mysql/mysql.sock
……

保存之后即出,重新启动 MySQL 。

via: http://www.chenruixuan.com/archives/517.html