Log in

View Full Version : Using cookies to keep a radio turned off



Moh
18-08-2008, 04:18 PM
If you own a site which dosn't use iframes or ajax, and want a radio player like Habbox, then why not use cookies :D

To do this, all you need is two pages. player.php and setplayer.php.

A demo of this can be found here (http://crazyvalues.net/cookieradioplayer).

player.php


<?php
$cookie_name = "RadioPlayer";

if($_COOKIE[$cookie_name]) {
?>
You have set the Radio not to play.<br>
<a href="setplayer.php?play=yes">Listen To the Radio</a>
<?
}
if(!$_COOKIE[$cookie_name]) {
?>
<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" standby="Loading" name="player" width="168" height="45" codebase="http://habbcrazy.net/CODEBASE=http:/activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715">
<param ref name="url" value="http://67.152.46.182:8002">
<param value="-1" name="autostart">
<param value="mini" name="uimode">
<param value="1" name="rate">
<param value="0" name="balance">
<param value="0" name="currentPosition">
<param value name="defaultFrame">
<param value="1" name="playCount">
<param value="0" name="currentMarker">
<param value="-1" name="invokeURLs">
<param value name="baseURL">
<param value="100" name="volume">
<param value="0" name="mute">
<param value="0" name="stretchToFit">
<param value="0" name="windowlessVideo">
<param value="-1" name="enabled">
<param value="-1" name="enableContextMenu">
<param value="0" name="fullScreen">
<param value name="SAMIStyle">
<param value name="SAMILang">
<param value name="SAMIFilename">
<param value name="captioningID">
<param value="0" name="enableErrorDialogs">
<embed name="player" uimode="mini" autoplay="true" url="http://www.habbcrazy.net/pages/radio/mediafile.asx" showstatusbar="false" controls="playbutton" autostart="True" src="mediafile.asx" width="168" height="45"></object>
<br>
<a href="setplayer.php?play=no" title="Stop the Radio">Stop the Radio</a>
<?
}
?>
setplayer.php


<?php
$cookie_name = "RadioPlayer";

if($_GET["play"] == "no") {
echo("The radio will stop playing for 31 days if your cookies are enabled.
Do you wish to continue?<br>
<a href=\"setplayer.php?stop=yes\" title=\"Yes\">Yes</a> | <a href=\"setplayer.php?stop=no\" title=\"No\">No</a>");
}
elseif($_GET["play"] == "yes") {
header('Location: setplayer.php?stop=no');
}
elseif($_GET["stop"] == "yes") {
setcookie($cookie_name, "stop_radio", time() + (30*24*60*60) );
header('Location: player.php');
}
elseif($_GET["stop"] == "no") {
$value = "stop_radio";
setcookie($cookie_name, "stop_radio", time() - 3600 );
header('Location: player.php');
}
else {
header('Location: player.php');
}
?>


Moved by Invent (Forum Moderator) from Designing & Development: Please post in the correct forum next time, thanks :).

Excellent1
18-08-2008, 05:05 PM
Great little script, + rep :)

Edit: I'd just cut the shortags due to some hosts now allowing them :P

Turbocom
18-08-2008, 06:41 PM
I was looking for this good job.

Agnostic Bear
19-08-2008, 03:40 AM
And now for some self contained code that doesn't suck:

1 file: player.php


<?php
$start = '';
$act = isset( $_GET[ 'act' ] ) ? $_GET[ 'act' ] : 'nothing';
switch( $act )
{
case 'stopconf':
setcookie( 'radio', 'no', time() + ( 31 * 24 * 60 * 60 ) );
break;

case 'start':
setcookie( 'radio', 'yes', '1000000000' );
$start = 'yes';
break;

case 'stop':
echo( 'The radio will stop playing for 31 days if cookies are enabled.
Do you wish to continue?<br>
<a href="player.php?act=stopconf" title=\"Yes\">Yes</a> | <a href="player.php" title="No">No</a>' );
break;
}

if( $_COOKIE[ 'radio' ] !== 'no' || $start === 'yes' )
{
echo( '<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" standby="Loading" name="player" width="168" height="45" codebase="http://habbcrazy.net/CODEBASE=http:/activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715">
<param ref name="url" value="http://67.152.46.182:8002">
<param value="-1" name="autostart">
<param value="mini" name="uimode">
<param value="1" name="rate">
<param value="0" name="balance">
<param value="0" name="currentPosition">
<param value name="defaultFrame">
<param value="1" name="playCount">
<param value="0" name="currentMarker">
<param value="-1" name="invokeURLs">
<param value name="baseURL">
<param value="100" name="volume">
<param value="0" name="mute">
<param value="0" name="stretchToFit">
<param value="0" name="windowlessVideo">
<param value="-1" name="enabled">
<param value="-1" name="enableContextMenu">
<param value="0" name="fullScreen">
<param value name="SAMIStyle">
<param value name="SAMILang">
<param value name="SAMIFilename">
<param value name="captioningID">
<param value="0" name="enableErrorDialogs">
<embed name="player" uimode="mini" autoplay="true" url="http://www.habbcrazy.net/pages/radio/mediafile.asx" showstatusbar="false" controls="playbutton" autostart="True" src="mediafile.asx" width="168" height="45"></object>
<br>
<a href="player.php?act=stop" title="Stop the Radio">Stop the Radio</a>' );
}
else
{
echo( 'You have turned the radio off<br>
<a href="player.php?act=start">Listen To the Radio</a>' );
}
?>

Calon
19-08-2008, 08:59 AM
I remember that Habbox use's this.

Pazza
19-08-2008, 10:50 AM
If you own a site which dosn't use iframes or ajax, and want a radio player like Habbox, then why not use cookies :D




I remember that Habbox use's this.

Looool,

Yeah ima be using this, very useful - I can barely ever find radio code let alone to stop it.

+rep

Moh
19-08-2008, 02:02 PM
And now for some self contained code that doesn't suck:

1 file: player.php


<?php
$start = '';
$act = isset( $_GET[ 'act' ] ) ? $_GET[ 'act' ] : 'nothing';
switch( $act )
{
case 'stopconf':
setcookie( 'radio', 'no', time() + ( 31 * 24 * 60 * 60 ) );
break;

case 'start':
setcookie( 'radio', 'yes', '1000000000' );
$start = 'yes';
break;

case 'stop':
echo( 'The radio will stop playing for 31 days if cookies are enabled.
Do you wish to continue?<br>
<a href="player.php?act=stopconf" title=\"Yes\">Yes</a> | <a href="player.php" title="No">No</a>' );
break;
}

if( $_COOKIE[ 'radio' ] !== 'no' || $start === 'yes' )
{
echo( '<object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" standby="Loading" name="player" width="168" height="45" codebase="http://habbcrazy.net/CODEBASE=http:/activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715">
<param ref name="url" value="http://67.152.46.182:8002">
<param value="-1" name="autostart">
<param value="mini" name="uimode">
<param value="1" name="rate">
<param value="0" name="balance">
<param value="0" name="currentPosition">
<param value name="defaultFrame">
<param value="1" name="playCount">
<param value="0" name="currentMarker">
<param value="-1" name="invokeURLs">
<param value name="baseURL">
<param value="100" name="volume">
<param value="0" name="mute">
<param value="0" name="stretchToFit">
<param value="0" name="windowlessVideo">
<param value="-1" name="enabled">
<param value="-1" name="enableContextMenu">
<param value="0" name="fullScreen">
<param value name="SAMIStyle">
<param value name="SAMILang">
<param value name="SAMIFilename">
<param value name="captioningID">
<param value="0" name="enableErrorDialogs">
<embed name="player" uimode="mini" autoplay="true" url="http://www.habbcrazy.net/pages/radio/mediafile.asx" showstatusbar="false" controls="playbutton" autostart="True" src="mediafile.asx" width="168" height="45"></object>
<br>
<a href="player.php?act=stop" title="Stop the Radio">Stop the Radio</a>' );
}
else
{
echo( 'You have turned the radio off<br>
<a href="player.php?act=start">Listen To the Radio</a>' );
}
?>

you always get one ;)

Want to hide these adverts? Register an account for free!