Lios Posted January 1, 2008 Share Posted January 1, 2008 Hello all, I hope you can help me. I am looking for a piece of code to do the following: When a user enters my site, a welcome sound should be played (currently in mp3, but can be any format). This should only be heard once per session (so not when users go through the menu or back to the homepage). Furthermore, users needs to be able to turn it off for that session,so they can stop it before the music ends, and they should be able to turn it off forever, so that it won't play when they revisit the site ever again. I bet it's possible with sessions and cookies, but i'm too much of a noob programmer to do so. Can anyone help me out? Quote Link to comment https://forums.phpfreaks.com/topic/83981-play-sound-once-per-session-or-not-at-all-when-users-turn-it-off/ Share on other sites More sharing options...
chantown Posted January 1, 2008 Share Posted January 1, 2008 When they enter site, flag it $_SESSION['playedmp3'] = true; then everytime you load a page, check it. if(!$_SESSION['playedmp3']) play song. Quote Link to comment https://forums.phpfreaks.com/topic/83981-play-sound-once-per-session-or-not-at-all-when-users-turn-it-off/#findComment-427437 Share on other sites More sharing options...
Lios Posted January 2, 2008 Author Share Posted January 2, 2008 Yes, but this only makes it play once per session. I also want people to be able to turn it off immediatly and (other option) forever. How does that work? Quote Link to comment https://forums.phpfreaks.com/topic/83981-play-sound-once-per-session-or-not-at-all-when-users-turn-it-off/#findComment-428054 Share on other sites More sharing options...
PC Nerd Posted January 2, 2008 Share Posted January 2, 2008 well you have a database field for `playmusic` then you simply go: if($DB['playmusic'] == 1 && $_SESSION['playedmp3'] == 0) { PLAY MUSIC } gdlk Quote Link to comment https://forums.phpfreaks.com/topic/83981-play-sound-once-per-session-or-not-at-all-when-users-turn-it-off/#findComment-428056 Share on other sites More sharing options...
chantown Posted January 3, 2008 Share Posted January 3, 2008 use a database. Whenever someone chooses to stop playing, $q = "UPDATE user_table SET play_music = 0 WHERE user = '$userID';" Quote Link to comment https://forums.phpfreaks.com/topic/83981-play-sound-once-per-session-or-not-at-all-when-users-turn-it-off/#findComment-428836 Share on other sites More sharing options...
Lios Posted January 3, 2008 Author Share Posted January 3, 2008 But to save that in a database, would mean the person has to login, otherwise i won't know if it's the same person, right? Or can you store that in a cookie on the user's computer? Quote Link to comment https://forums.phpfreaks.com/topic/83981-play-sound-once-per-session-or-not-at-all-when-users-turn-it-off/#findComment-429307 Share on other sites More sharing options...
jordanwb Posted January 3, 2008 Share Posted January 3, 2008 You could use a cookie but that would last only so long. Cookies timeout after a set period of time. Quote Link to comment https://forums.phpfreaks.com/topic/83981-play-sound-once-per-session-or-not-at-all-when-users-turn-it-off/#findComment-429315 Share on other sites More sharing options...
chantown Posted January 3, 2008 Share Posted January 3, 2008 cookies are a good way to do it Or you can use IP Quote Link to comment https://forums.phpfreaks.com/topic/83981-play-sound-once-per-session-or-not-at-all-when-users-turn-it-off/#findComment-429328 Share on other sites More sharing options...
jordanwb Posted January 3, 2008 Share Posted January 3, 2008 I agree with chantown. IP seems to be the best way to go because since we got our Cable Modem from Rogers our IP has changed only one. Quote Link to comment https://forums.phpfreaks.com/topic/83981-play-sound-once-per-session-or-not-at-all-when-users-turn-it-off/#findComment-429331 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Don't we wish everyone was that easy? In the real world, IPs change all the time. It is unreliable and I wouldn't use it to do anything. I agree with chantown. IP seems to be the best way to go because since we got our Cable Modem from Rogers our IP has changed only one. Quote Link to comment https://forums.phpfreaks.com/topic/83981-play-sound-once-per-session-or-not-at-all-when-users-turn-it-off/#findComment-429335 Share on other sites More sharing options...
jordanwb Posted January 3, 2008 Share Posted January 3, 2008 In the real world, IPs change all the time. That is true. Before Rogers we had Sympatico (which was horible), and everytime we connected we got a new IP. So really there is no one sure way to do it. Quote Link to comment https://forums.phpfreaks.com/topic/83981-play-sound-once-per-session-or-not-at-all-when-users-turn-it-off/#findComment-429364 Share on other sites More sharing options...
chantown Posted January 5, 2008 Share Posted January 5, 2008 the only way is to use cookies and/or ip. i suggest both or a login Quote Link to comment https://forums.phpfreaks.com/topic/83981-play-sound-once-per-session-or-not-at-all-when-users-turn-it-off/#findComment-431280 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.