Hiding content from internal links or using cookies

Hello everyone,

I have a problem and I’m a real newbie with PHP.
My client forced me into putting a flash animation that pops in a thickbox when a visitor visits the homepage. He also wants that the animation doesn’t appear when the visitor returns to the homepage from a link in the website.

I don’t know how to detect a referrer from the website. Everything I tried (using http_referer) also hid the animation when the visitor entered the URL in the adress bar.

I’m also open using cookies, which is what I’m trying right now. The cookies solution I have works in Firefox but not on IE browsers, I don’t know if it’s a browser config problem or not, but it doesn’t work at my client side.

Here is my current solution:

<?php
if(isset($_COOKIE['animintro'])){ ?>
<?php } else {
    $two_months = 60 * 60 * 1 * 0 + time(); 
    setcookie('animintro', true, $two_months);
    ?>
<script type="text/javascript">
window.onload = function() {
var options = {
              overlayColor: '#000000',
              overlayOpacity: 0.9,
              flashVars:{quality:'high',classid:'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'}, flashParams:{quality:'high',classid:'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000'}
            };
          Shadowbox.init(options); 
// open a welcome message as soon as the window loads
Shadowbox.open({
content: 'http://www.example.com/shop/skin/frontend/default/blank/flash/animation-accueil.swf',
player: 'swf',
height: 403, width: 623
});
};
</script>
<?php } ?>

Anyone has an idea? Thanks in advance.

You can get that information from the superglobal array “$_SERVER”. The index name is “HTTP_REFERER”.

I test for a session counter which starts at zero and increments by one after each page load:



  session_start();
  $_SESSION['counter'] = ìsset($_SESSION['counter'] ) ? 1 +   $_SESSION['counter']  : 0;

  if (  $_SESSION['counter']  == 0)
  {
    // first time so show whatever
  }


@John_Betong: thanks a lot it worked!
If anyone looks at using this for Magento in particular, the session is already started, so no need to use

session_start();

. You should also change the “ì” in isset and replace it with a “i”.

@Amit Yaron: I tried using the “_SERVER” array but it didn’t work. Maybe I did it wrong…

'glad I was able to help.

The “í” instead of the “i” is due to keyboard settings which I will hopefully one fine day discover the problem :slight_smile: