PLAYING A SOUND FILE ONCE A SESSION - Dec 31st, 2012


I recently had a request to play a greeting message only the first time a visitor accessed my client’s site. My client
was OK with the idea that the “first time” could be defined by opening the visitor’s browser. I wanted to avoid
using Javascript and stick with PHP, so here’s what I found. Hope it proves useful.

This code gets placed a the very head of your page, before the “require once” code.



<?php setcookie("firsttime","no") ?>



And this code gets placed right after your <body> tag



<?php
$firsttime = $_COOKIE[firsttime];
if (@
$firsttime != "no") { echo "<embed src='http://www.yoursite.com/yourgreeting.mp3' width=0 height=0 />"; }
?>



The width and height are set to “0" so that the player is invisible on the page.

But what if you wanted to play the sound once a day instead of once a session? The answer is in the next recipe.



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service