我正在尝试在 javascript 获取 CORS 请求中将 Cookie 发送到 PHP 脚本。请求开始https://sub1.example.com并包含以下选项:
let response = await fetch('https://sub2.example.com/target.php', {
method: "POST",
headers: headers,
body: formData,
mode: 'cors',
credentials: 'include',
cache: 'no-store'
});
Run Code Online (Sandbox Code Playgroud)
相应的 PHP 脚本设置以下 headers:
header('Access-Control-Allow-Origin: https://www.example.com');
header('Access-Control-Allow-Methods: POST, OPTIONS');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, X-Request-With, Set-Cookie, Cookie, Bearer');
Run Code Online (Sandbox Code Playgroud)
但 Cookie 标头不随请求一起发送。我也尝试过:
let headers = new Headers();
headers.set('Cookie', document.cookie);
Run Code Online (Sandbox Code Playgroud)
这也没有效果。我到底做错了什么?
我检查了开发工具中的网络选项卡。$_COOKIEPHP脚本中也是空的。绝对没有错误。我还可以看到 Cookie 标头是在任何非 CORSfetch请求中发送的。
编辑:以下是其中一项 Cookie 的设置:
Name: PHPSESSID
Path: /
Secure: true
SameSite: none …Run Code Online (Sandbox Code Playgroud) 当使用 PDO::PARAM_INT 传递字符串时,PHP 7.2 中的行为似乎发生了变化。在版本 7.1 中更新的值和传递的字符串是相同的,在 PHP 7.2 中更新的值是“3”(见下面的例子)。
当然,我知道使用 PDO::PARAM_INT 传递字符串是错误的,但我想知道为什么在 PHP 更改日志中找不到任何内容以及为什么没有抛出异常或警告。
有谁知道这是否是一种理想的行为?
$sql = "UPDATE test SET name = :name WHERE id = 1";
$update = $db->prepare($sql);
$update->bindValue(':name', '3hgsf5-458752shUGVZCF', PDO::PARAM_INT);
$update->execute();
Run Code Online (Sandbox Code Playgroud)