将JavaScript变量传递给php? [英] Passing javascript variables to php?
问题描述
好的,所以我试图将javascript变量放入php脚本中,这将是一个示例,
ok so im trying to get a javascript variable into a php script, this would be an example,
<script type="text/javascript">
x = new Date()
</script>
<?php
$x = $_GET["x"];
?>
<p><?php echo $x ?></p>
我就是无法正常工作!我需要帮助吗?
i just cant get it to work! I need help please?
好吧,我只是想通过javascript从网址中获取哈希值,然后将其放入php脚本中.
well im just trying to get the hash from a url via javascript then put that in a php script.
推荐答案
PHP和javascript不能那样工作.
PHP and javascript don't work like that.
PHP是一种服务器端语言. javascript是一种客户端语言.
PHP is a server-side language. While javascript is a clientside language.
仍然存在通过ajax,查询参数,cookie将数据从客户端窗口传递到服务器的方法,但是在同一页面上都无法使用.
There are still ways of passing data from the client-window to your server, via ajax, query parameters, cookies... But none will work in the same page.
让我们对您要达到的目标有更清晰的了解,我们将很乐意为您提供帮助.
Give us a clearer image on what you are trying to achieve and we will gladly help.
更新
JS
<script type="text/javascript">
document.cookie = 'name=Khez' ;
</script>
PHP
<?php
var_dump($_COOKIE['name']);
?>
这篇关于将JavaScript变量传递给php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!