检测何时访问页面更改图像 [英] Detect when page has been visited change image

查看:83
本文介绍了检测何时访问页面更改图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道:visited存在一些问题,所以现在我正在寻找一种替代方法.我想知道用户是否可以访问我网站上的某个页面,一旦他们返回首页,就会显示不同的图像.

I know there are a few issues with :visited and so now I'm looking for an alternative. I'd like to know if it's possible for a user to visit a certain page on my website and once they go back to the homepage, a different image shows up.

更新:主页中有图像,当您单击图像时,它会变为新图像,表明您已访问该页面.但是,如何检测您是否在网站的另一页上,而无需单击图像就可以访问链接?我仍然希望该事件触发更改.那有可能吗?

Update: there are images in the homepage, when you click on one, it changes to a new one, indicating you've visited the page. BUT how do you detect if you are on another page of the site and you visit the link without clicking the image? I still want the event to trigger the change. Is that even possible?

推荐答案

<?php
// Code to put in every page.
if (session_name() == "")
    session_start();    
    if (!isset($_SESSION['visited']))
        $_SESSION['visited'] = array(); //Init.
    $current_page = "current_page"; // Set the page here.       
    if (!$_SESSION['visited'][$current_page])
        $_SESSION['visited'][$current_page] = 1;

?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Page</title>
</head>

<body>
<?php foreach ($pages as $page) : ?>
<?php if ($_SESSION['visited'][$page]) : ?><p>Image 1</p><?php else : ?><p>Image 2</p><?php endif ?>
<?php endforeach ?>
</body>
</html>

使用PHP会话应该可以.

Using PHP Sessions it should work.

这篇关于检测何时访问页面更改图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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