How to Create a Robust Splash Page

Sending a user to a 'splash' page the first time they visit your site seems like a pretty simple task, but its not. At first glance I thought it would easily work a bit like this:

  • Set a cookie on the 'splash' page using say: setcookie() that doesn't expire for a very long time
  • Check on every other page if the cookie exists on the users browser, if not, send them to visit your splash page

This is not robust enough though, if the users' browser has cookies turned off then they will enter an infinite loop and end up endlessly visiting the splash page - not a very good thing for search engine spiders to do.

 

So, you need to test if the cookies are turned off on the users browser before you do any redirecting or anything. As it turns out the best test is to set a dummy cookie and then verify its existence with javascript. You can't easily perform this test using php, because, by the time you set the cookie everything is at the browser and php has finished performing its tasks - so without having to reload every page relying on Javascript is the easiest solution.

The right way to do a splash page:

So, if all goes well, set a dummy cookie on the page requested using php or javascript.
Verify its existence with javascript once the page has loaded, then you know that the browser accepts cookies you can move onto the next step of checking whether the cookie exists that indicates the user has viewed the splash page.

If that cookie does not exist then send the user to your splash page to view.

This will in effect send users to your 'splash' page the first time they visit your site. However, if the user's browser has cookies or javascript turned off, or both, then they will never see your splash page. Which means search engine spiders will never see the splash page either, although some of them might know that the javascript redirect is there ;).

Download the Splash Page Script:

As you can see in the scripts I have used a Javascript Cookie Script from techpatterns.com which was incredibly simple to implement, as you can also see from the scripts that I like simple :)

Update:

The download was not working, however, it should now.