防止用户打开同一网站的多个实例 [英] Prevent users from opening multiple instance of same website

查看:131
本文介绍了防止用户打开同一网站的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要网上PHP和JS脚本的帮助。

I need help with PHP and JS scripting on web.

我试图做的就像购物车。产品信息通过url参数传递并存储在PHP中的SESSIONS中。 (例如 http://www.mysite.com/pid=13

What I'm trying to do is something like a shopping cart. The product info is passed through the url paramaters and stored into SESSIONS in PHP. (Eg. http://www.mysite.com/pid=13)

如果用户在浏览器中打开新选项卡并加载 http:/ /www.mysite.com/pid=25 ,第二个标签会显示更新的购物车,其中包含2个项目,但第一个标签只会显示1个项目,除非我手动刷新它。

If the user opens a new tab in browser and loads http://www.mysite.com/pid=25, the second tab will show the updated cart with 2 items, but the first tab will only show 1 item unless I manually refresh it.

我需要的是:

What I need is:


  1. 当用户第一次访问我的网站时,信息将被加载。

  2. 当用户在浏览器中打开同一网站的另一个实例(相同的网址)时(例如新标签),第二个实例将被关闭,第一个实例将被刷新以加载一些更新的信息。
  1. When the user visits my site on the first time, information will be loaded.
  2. When the user opens another instance of the same site (same url) on the browser (eg new tab), the second instance will be closed and the first instance will be refreshed to load some updated information.

简单地说,我不希望用户通过强制关闭在同一浏览器中打开我的站点的多个实例第二个选项卡并刷新第一个选项卡。有什么办法可以做到这一点使用PHP和JS的组合?

In simple terms, I do not want the user to open multiple instance of my site in the same browser by force closing the second tab and refreshing the first tab. Is there any way I can do this using a combination of PHP and JS?

推荐答案

从你的问题我相信你添加项目s)通过'get'购物车。
我建议你通过'POST'
添加,而不是把你的唯一ID和其他项目相关的数据以隐藏的形式。
例如:

From your question I believe you add item(s) to cart via 'get'. I would suggest you add via 'POST' instead put your unique id and other item related data in a hidden form. eg:

<form action="add_to_cart.php" method="post">
<p>Some Item Name</p>
<input type="hidden" name="item_name" value="Some Item Name" />
<p>Description: SOME DESCRIPTION</p>
<input type="hidden" name="description" value="Some Description" />
<p>Price: $123.00</p>
<input type="hidden" name="price" value="123.00" />
<input type="hidden" name="item_id" value="123" />
<!-- GENERATE TOKENS FOR YOUR FORM TO PREVENT XSS / CSRF attack -->
<input type="hidden" name="token" value="somerandomtoken" />
<input type="submit" name="add_to_cart" value="Add to Cart" />
</form>

在这种情况下,用户只能通过提交此表单将商品添加到购物车。
希望这有助于。

In this case User can only add item to cart by submitting this form. Hope this helps.

这篇关于防止用户打开同一网站的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆