2012-03-14 20 views
0

我知道有几个问题:访问,所以现在我正在寻找替代品。我想知道用户是否可以访问我网站上的某个页面,并且一旦他们返回主页,就会看到不同的图像。检测页面已被访问更改图像

更新:主页上有图片,当你点击一个图片时,它会变成一个新图片,表示你已经访问过该页面。但是如何检测您是否在网站的另一个页面上,并且在没有点击图片的情况下访问该链接?我仍然希望事件触发变化。这甚至有可能吗?

+0

不同你的意思是每次都加载一个随机图像吗?否则你的意思是第一次访问者有特定的图像,而重复访问者有不同的特定图像? – Kristian 2012-03-14 02:16:38

回答

0
<?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会话它应该工作。

+0

谢谢,这真是太棒了。 – iliketurtles 2012-03-14 19:21:03

0

你可以有图像源

images = []; 
    images[1] = "src of pic1"; 
    images[2] = "src of pic2"; 
    //you can have more links if you want 

    size = images.length; 
    rNum = Math.floor(Math.random()*size); 

    document.getElementById("img").src = images[rNum]; 
0

在访问该页面时,应该设置会话cookie的数组。

This是一个很棒的jQuery插件。

首页代码

$(function(){ 
    if($.cookie("interior_page_visited")){ 
    //display new image 
    } else { 
    //display initial homepage image 
    } 
}); 

内部网页代码

$(function(){ 
    //set cookie, expires when browser is closed 
    $.cookie("interior_page_visited", true); 
}); 
+0

这一个也适用,但如果他们禁用JavaScript呢?非常感谢你的帮助。 – iliketurtles 2012-03-14 19:20:48