小编Sam*_*hid的帖子

Php PDO功能的安全性如何:lastInsertId?

我对Php PDO函数几乎没有什么困惑:lastInsertID.如果我理解正确,它将返回插入数据库中的最后一个自动增量ID.

当我在创建注册用户的功能时执行在数据库中插入用户的查询时,我通常使用此函数.

我的问题是,例如,我有一百人在我的网站上注册.并且可能是一个用户在另一个用户之后的一毫秒内点击"注册"按钮.那么这个函数lastInsertId是否有可能返回另一个刚刚注册的用户的id?

可能是我想问的是服务器一次处理一个请求并一次通过一个php文件?

请让我知道这件事.

谢谢.

php pdo

7
推荐指数
2
解决办法
849
查看次数

为什么我们需要在bindParam()中指定参数类型?

我有点困惑为什么我们需要指定在 Php 的 PDO 中的 bindParam() 函数中传递的数据类型。例如这个查询:

$calories = 150; 
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < ? AND colour = ?');
$sth->bindParam(1, $calories, PDO::PARAM_INT); 
$sth->bindParam(2, $colour, PDO::PARAM_STR, 12);
$sth->execute();
Run Code Online (Sandbox Code Playgroud)

如果不指定第三个参数,是否存在安全风险?我的意思是如果我只是在 bindParam() 中执行以下操作:

$sth->bindParam(1, $calories); 
$sth->bindParam(2, $colour);
Run Code Online (Sandbox Code Playgroud)

php pdo sql-injection

6
推荐指数
1
解决办法
2614
查看次数

bcrypt和随机生成的盐

所以我正在试验bcrypt.我有一个类(如下所示,我从http://www.firedartstudios.com/articles/read/php-security-how-to-safely-store-your-passwords获得),其中有3个函数.第一个是生成随机Salt,第二个是使用第一个生成的Salt生成哈希,最后一个是通过将其与哈希密码进行比较来验证提供的密码.

<?php
/* Bcrypt Example */
class bcrypt {
    private $rounds;
    public function __construct($rounds = 12) {
        if(CRYPT_BLOWFISH != 1) {
            throw new Exception("Bcrypt is not supported on this server, please see the following to learn more: http://php.net/crypt");
        }
        $this->rounds = $rounds;
    }

    /* Gen Salt */
    public function genSalt() {
        /* openssl_random_pseudo_bytes(16) Fallback */
        $seed = '';
        for($i = 0; $i < 16; $i++) {
            $seed .= chr(mt_rand(0, 255));
        }
        /* GenSalt */
        $salt = substr(strtr(base64_encode($seed), '+', …
Run Code Online (Sandbox Code Playgroud)

php salt bcrypt password-encryption

5
推荐指数
1
解决办法
3256
查看次数

带有ENT_QUOTES和UTF-8的htmlentities有什么作用?

我一直使用简单的htmlentities($_POST['string']);方法清除任何XSS攻击的数据。最近,我看到人们使用此方法:

htmlentities($_POST['string'], ENT_QUOTES, 'UTF-8');
Run Code Online (Sandbox Code Playgroud)

有什么优势或者利用经过短短的目的htmlentities()

另外也不知道它是否相关,但是我总是在页面顶部使用meta UTF-8。

php xss encode html-entities

4
推荐指数
1
解决办法
8835
查看次数