简体   繁体   English

发送一个javascript变量到PHP cookie变量

[英]Sending a javascript variable to php cookie variable

The code is like this, however it seems not to be working. 代码是这样的,但是似乎无法正常工作。 Please help 请帮忙

<script type="text/javascript">

var name=prompt("Please enter your name");
</script>
<?php

$_COOKIE['user']=$_GET['name'];
?>

You are mixing PHP (which runs on server side) with JavaScript (which runs on client side). 您正在将PHP(在服务器端运行)和JavaScript(在客户端运行)混合在一起。 This is fundamentally impossible. 从根本上讲这是不可能的。 PHP is run long before the JavaScript part. PHP在JavaScript部分之前运行了很长时间。

You probably want to use JavaScript to set the cookie . 您可能想使用JavaScript 设置cookie PHP will be able to read it on the next request. PHP将能够在下一个请求时读取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM