使用会话或 cookie 显示/隐藏 div
我需要隐藏或显示一个内部有幻灯片的 div。 这个想法是为用户提供一个隐藏或显示 div 的链接。
目前,我使用
用户单击链接以隐藏/显示 div 后,我想调用第二个文件( ) 其中包含不同的 div。
据我发现,没有办法通过会话来实现这一点,或者至少我没有找到解决这个问题的方法。
我的猜测是这需要用cookie来完成,但我不明白如何做。
I need to hide or show a div that have a slideshow inside.
The idea is to give to the users a link for them to hide or show the div.
At the moment I call the slideshow on the body of the page with <?php include('slideshow.php'); ?>
After the user clicks on the link to hide/show the div I will like to call a second file (<?php include('no-slideshow.php'); ?>
) which contain a diferent div.
As far as I had found there is no way to achieve this with sessions, or at least I did't find a solution to this problem.
My guess is that this need to be done with cookies, but I don't understend how.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不想使用 JavaScript,实现这一点的唯一方法是使用链接(需要重新加载页面)。
这只是基本逻辑,不是完整的解决方案,但我想您会明白的。
在网页上创建到服务器端脚本的链接。
创建脚本togle_visibility.php来处理用户的请求。
您现在所需要做的就是(返回原始页面后)检查 cookie 中存储的值并决定是否不向用户显示该 div。
编辑:$hidediv 条件。
如果用户禁用了 JavaScript,则该方法有效,但如果在浏览器设置中禁用了 cookie,则该方法无效。
我没有检查此代码,因此可能存在相同的拼写错误。
If you don't want to use JavaScript only way to achieve that is to use link (requires page to be reloaded).
This is basic logic only, not a complete solution, but think you'll get the point.
Create a link on web page to the server-side script.
Create script togle_visibility.php to process user's request.
All you need now (after return to original page) is to check value stored in cookie and decide do you want od not to show that div to do user.
EDIT: $hidediv condition.
It works if user has JavaScript disabled but doesn't work if cookies has been disabled in browser settings.
I did not check this code, so same typos are possible.
我不确定我是否理解了。您想在用户点击链接后隐藏 div 吗?
你为什么不使用 javascript 来做到这一点? (隐藏/显示 div?)
I am not sure I understood. You want to hide div once user cliks on a link?
Why are you not doing this using javascript? (hide/show the divs?)
此命令将设置一个名为
include
的cookie具有值要包含的内容
。您可以在包含之前检查此 cookie,如下所示:
注意:由于 cookie 很容易被伪造,因此您需要检查两次要包含的内容。
This command will set a cookie named
include
with valuewhat to include
.You can check this cookie before include like this:
Note: because cookies can be easily faked you'll need to check twice what to include.