将javascript值的内容获取到php变量中?

发布于 2024-11-16 00:46:54 字数 171 浏览 1 评论 0原文

我有一个客户需要使用只能通过 javascript 提供的特定跟踪。他希望能够捕获在客户端打印的完全相同的信息。

我如何将其添加到现有的 php 脚本中以将数据添加到数据库中?我唯一的想法是直接在主脚本中回显 javascript,但我似乎无法弄清楚如何从 php 回显中获取值。

有什么想法吗?

i have a client who is required to use specific tracking that is only made available through javascript. he wants to be able to capture the exact same information being printed on the client side.

how can i add this into the existing php script to add the data into the database? my only idea was to echo the javascript directly inside the main script, but i can't seem to figure out how to get the values out of the php echo.

any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

好听的两个字的网名 2024-11-23 00:46:54

这实际上是不可能的,您需要执行 AJAX 调用才能获得类似的东西。

我建议直接用 PHP 实现代码,而不是依赖 Javascript 获取数据。

It's not really possible, you'd need to do an AJAX call to get something similar.

I suggest implementing the code in PHP directly rather then reliying on Javascript for data.

扛刀软妹 2024-11-23 00:46:54

您可以使用虚拟图像将其发送到服务器。

document.write('<img src="file.php?foo=value1?bar=value2&...">');

file.php 的内容

<?PHP 
Header("Content-type: image/png"); 

do something with $_GET['foo']

?> 

这不是最好的方法,但它很快并且可以工作。

You can send it to the server using a dummy image.

document.write('<img src="file.php?foo=value1?bar=value2&...">');

contents of file.php

<?PHP 
Header("Content-type: image/png"); 

do something with $_GET['foo']

?> 

It's not the best way, but it's fast and it will work.

别挽留 2024-11-23 00:46:54

这是不可能的,因为客户端脚本不能直接与服务器端脚本交互,因此它需要你在两者之间有一个“传输器”,即阿贾克斯。看看 jQuery AJAX,它小巧、可爱且功能强大。

但假设有一小块信息,并且不是很机密,我可以建议您使用 cookie 来这样做。人们通常不会利用cookie。

<script type="text/javascript">
document.cookie = 'info='+information; expires=Mon, 19 Jul 201110:00:00 UTC; path=/';
</script>

在 PHP 文件中

<?php
if (isset($_COOKIES['info'])) {
   $information= intval($_COOKIES['info']);
}
?>

获取信息后,您可以删除该 cookie。

It is not possible, because client-side script can NOT interact directly with server-side script, therefore it requires you to have a "transporter" in the between, which is AJAX. Have a look at jQuery AJAX, it's tiny, sweet and powerful.

But assume there is a small chunk of information, and it's not very confidential, I can suggest you to do this way, using cookies. People don't usually take advantage of cookies.

<script type="text/javascript">
document.cookie = 'info='+information; expires=Mon, 19 Jul 201110:00:00 UTC; path=/';
</script>

In PHP file

<?php
if (isset($_COOKIES['info'])) {
   $information= intval($_COOKIES['info']);
}
?>

Once you finish getting the information, you can delete that cookies.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文