How to Load Animated Flash Header One Time During the Session

fter a client had made a request for a Flash header to not animate every time a new page is loaded, I needed to figure out how to do this. Not for this one request, but for any future requests. I have previously looked this up, but came up empty. It seemed there was one solution, but it really wasn’t the greatest, because when you return to the home page, the animation would play again.

I eventually came across a solution that had no comments from other people, so I didn’t really know if it would work. The person who provided the solution also provided a link to his/her website with it in action, so I was able to see that it worked.

This solution uses PHP sessions. It works by displaying the full Flash header only if never viewed during the current session. If it has already been viewed, it will display the second (non-animated) header until the session ends, which is on browser close. The next time the website is viewed in a new session, it will display the original animated header.

The first code you need to add is placed at the top, before any other code (DOCTYPE & HTML), in the header. This code checks to see if there are any views during the current session.

< ?php
if (isset($_SESSION['views']))


The next code is for displaying the Flash, just as you would normally, except it’s using PHP.

< ?php if ($_SESSION['views']>1) //if session views are more than one
echo "Flash embed code here";
else //if session view is one
echo "Flash embed code here";

This code is just saying: If views are more than one, display the second (non-animated) header. If views are one, display the full animated header. It is really simple.

Make sure to remove the space that appears at the beginning of the PHP code: < ?php. Also, when adding the Flash embed code to be echoed, escape any quotes with a ‘\’ (without the single quotes).

Full credit for this solution goes to The actual solution is in the Coffee Cup forums.

Posted in: Tutorials