0

On MY website, I have a animation that I only want it to play once when the use first visit the website. So I set up a session to check if the user visit for the first time. Below is my code:

if(!isset($_SESSION["playedit"]))
session_start();

if(isset($_SESSION["playedit"]))
$_SESSION["playedit"] = false;
else
$_SESSION["playedit"] = true;



<?php if($_SESSION["playedit"]){?>
  //play animation

<?php } ?>

It's working on IE but for firefox and chrome, the animation always play twice. I don't know what's going on. Here the website: ryandang.com . I want the header animation to play only once

by play twice, I meant when user go to another page, it plays again

Oh it also work on my local machine. It just doesn't work on the host server. Do you think it has something to do with the host server?

Edit1: Here is the catch I just found out, If I access my site with link like ryandang.com/games or ryandang.com/works, It only play once. However, if I use ryandang.com which go to my index.php page which has 1 line of code header('Location: aboutme'); It will play twice!

4

1 回答 1

1

您需要在每个页面中执行 session_start() 。这不应该依赖于另一个变量的存在。所以删除第一行。

现在,将您的代码简化为:

session_start();

<?php if(isset($_SESSION["playedit"])==false){?>
   $_SESSION["playedit"] = 'something';
  //play animation

<?php } ?>
于 2013-09-28T15:26:56.207 回答