uwMike.com

I'm in Waterloo at the moment, and next available to work in September 2008.

One-Time Forwarding in PHP

December 21st, 2004

Or ‘how to make a splash-screen that won’t excessively annoy your users’.

This isn’t a perfect mechanism, but I think it works pretty well, and it avoids any dreaded client-side Javascript-forwarding.

So the goals were:

  • when the user visits the homepage, forward automatically to the splash page.
  • when the user visits consecutive times, such as by following a link from the splash-page, do _not_ forward.

The obvious solution is to use a cookie to store whether they’ve seen it. But there’s an obvious problem with this approach: If the user has disabled cookies, they will always be forwarded and the main content will be inaccessible to them.

The answer would seem to be simply: Set a cookie, then force a reload and check if the cookie exists. But that wastes everyone’s time when the cookie can simply be checked from the splash page.

The code is as follows. At the top of the main index.php file, goes:

if (!isset($_GET['nosplash']))
  if (!(isset($_COOKIE['splashseen'])))
  {
    setcookie(’splashseen’, ‘1′, time()+60*60*24, ‘/’);
    header(”Location: /special/christmas2004/?splash”);
  }

And inside the splashpage’s index.php,


if (isset($_GET['splash']))
  if (!(isset($_COOKIE['splashseen'])))
    header(”Location: /?nosplash”);

This way, non-cookie users never see the splashpage at all. But that’s better than only seeing it. If you missed it, here it is.

Mike

Discussion

  1. Well, almost right - except I have to go through twice - the first time I hit enter, I get redirected back to the splash. The next time works.

    Something isn’t registering the first time.

    Posted at 4:02 pm on December 31st by Daniel.

  2. Interesting… I’ve tried it out on several different computers with cookies enabled and disabled and it seemed to be okay.

    What kind of setup are you on? (I know, if I was l33t enough, I could probably figure out your browser and OS by just checking the logs, but that would require effort…)

    I better figure out this cookie business, cause one of the next features I want to implement is the opportunity to save the comment-identity fields in a cookie.

    Posted at 4:02 pm on December 31st by Mike.

  3. I’m using firefox - I’ve had it happen both windows and linux.

    Posted at 4:02 pm on December 31st by Daniel.

  4. I must just tell you how much I hate the consept of splash screen. I hate it in webpages, I hate it in software. People want to get to the stuff at once. People will probably hit enter, but the more stuff people must click through to get want they want the more annoyed they will get. Even if it is a one time splash screen.

    Posted at 4:02 pm on December 31st by Jon Berg.

  5. I don’t like permanent ones, but for example, SomethingAwful occasionally does a humorous parody of their own or someone else’s homepage, where every link leads to the actual page — usually containing an apology for anyone freaked out by the change.

    Many, many personal homepages follow the formula of free blog tool + free gallery tool + custom homepage linking to both. This is extremely frustrating, since in almost every case, it’s very easy to just hack up the blog tool’s homepage to include recent thumbs, or even just a link (the blog is usually going to be updated much more frequently than the gallery).

    Even some extremely able designers have followed this approach, while in the case linked, the gallery and blog softwares are custom pieces of work loaded with innovations not available in free ones.

    The gallery of this site is still forthcoming, but… but, well, you’ll see it when it’s here.

    Posted at 4:02 pm on December 31st by Mike.

Leave a Reply

You can use Markdown for style. I love hearing from readers, but please don’t hijack the discussion, use offensive language, or try to sell anything.

© 2004-2008, Mike Purvis, some rights reserved. I'm running Wordpress, and I have an RSS feed.