PHP 魔术常量 PHP 向它运行的任何脚本提供了大量的预定义常量。 不过很多常量都是由不同的扩展库定义的,只有在加载了这些扩展库时才会出现,或者动态加载后,或者在编译时已经包括进去了。 有八个魔术常量它们的值随着它们在代码中的位置改变而改变。 例如 __LINE__ 的值就依赖于它在脚本中所处的行来决定。这些特殊的常量不区分大小写,如下: __LINE__ 文件中的当前行号。 实例 <?php echo '这是第 " ' . __LINE__ . ' " 行…
安装 开始在 PHP 中使用 Redis 前, 我们需要确保已经安装了 redis 服务及 PHP redis 驱动,且你的机器上能正常使用 PHP。 接下来让我们安装 PHP redis 驱动: 下载地址为:https://github.com/phpredis/phpredis PHP安装redis扩展 以下操作需要在下载的 phpredis 目录中完成: git clone https://github.com/phpredis/phpredis.git cd phpredis-3.1.4 # 进入 phpr…
HTML定义文件上传组件和上传按钮,使用了 Bootstrap ,不满意可以自己美化。 <form id="form1"> <div class="form-group"> <div class="custom-file"><input id="fileUpload" class="custom-file-input" type="file" /> …
现在很多人喜欢用md5或md5+salt加密密码存储在数据库中,从技术的角度来说,MD5真的安全,因为MD5是不可逆的,没办法解密,除了撞库这样的方式。关于撞库简单来说就是通过建立大型数据库,将常用的各种句子密码等加密成为密文,并存储在数据库中;然后拿着密文到数据库网站查询,就有可能查到密码。 但在PHP中有更好的密码存储方式:Password Hashing,主要用到了4个函数: //查看哈希值的相关信息 array password_get_info (string $hash) //创建hash密码 stri…
<?php // 非常给力的authcode加密函数,Discuz!经典代码(带详解) // 函数authcode($string, $operation, $key, $expiry)中的$string:字符串,明文或密文;$operation:DECODE表示解密,其它表示加密;$key:密匙;$expiry:密文有效期。 function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0…
/** * 通过UTC获取精确时间,默认为北京时间 * @param int $timezone * @param int $timestamp * @return bool|false|string */ public function getutctime($timezone = 8, $timestamp = 0) { $fp = fsockopen('time.nist.gov', 13, $err_no, $err_str, 90); $t = fread($fp, 2096); if…
/** * 缩略图生成函数,使用GD2 * @param $srcFile * @param $toW * @param $toH * @param string $toFile * @param string $default_ext * @return bool|string */ public function image_resize($srcFile, $toW, $toH, $toFile = "", $default_ext="png") { //error_r…
/** * 字符串加密 * @param $str * @param string $key1 * @param string $key2 * @return string */ function encode_z($str, $key1 = "", $key2 = "") { global $config; $b = array(); $c = array(); $s = ''; if (strlen($key1) != 16) $key1 = $con…