gpt4 book ai didi

php - 如何在 PHP 中获取 JavaScript 变量值

转载 作者:IT王子 更新时间:2023-10-28 23:46:57 25 4
gpt4 key购买 nike

我想要我可以使用 PHP 访问的 JavaScript 变量的值。我正在使用下面的代码,但它不会在 PHP 中返回该变量的值。

// set global variable in javascript
profile_viewer_uid = 1;

// php code

$profile_viewer_uid=$_POST['profile_viewer_uid'];

这给了我以下错误:-

A PHP Error was encountered
Severity: Notice
Message: Undefined index: profile_viewer_uid

我使用的另一个 php 代码给出了空值

$profile_viewer_uid = "<script language=javascript>document.write(profile_viewer_uid);</script>

当我回显时,它什么也没显示。

最佳答案

使用您要访问的 javascript 变量添加一个 cookie。

document.cookie="profile_viewer_uid=1";

然后通过 php 访问它

$profile_viewer_uid = $_COOKIE['profile_viewer_uid'];

关于php - 如何在 PHP 中获取 JavaScript 变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9789283/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com