Flawed GET/Cookie logic, need clarification...
Posted: Tue Aug 28, 2007 4:18 pm
My PHP logic arguments are flawed and I'm looking for clarification on what I'm screwing up here...
$_GET['audio'] has precedence over $_GET['audio'] unless there is no $_GET['audio']...I sort of have this functioning though I could definitely do a better job of clarifying it. I also know this code (even when we get it working) will not be anywhere close to ideal PHP code though I'm just trying to get the logic/script to work correctly. Audio values are 0 for no audio, 1 for dialup, and 2 for broadband. This script is exclusive to only determining if a broadband audio link should be provided or not based on the visitor's preference. Also I'm providing some additional code to help with testing below...
header.php example
$_GET['audio'] has precedence over $_GET['audio'] unless there is no $_GET['audio']...I sort of have this functioning though I could definitely do a better job of clarifying it. I also know this code (even when we get it working) will not be anywhere close to ideal PHP code though I'm just trying to get the logic/script to work correctly. Audio values are 0 for no audio, 1 for dialup, and 2 for broadband. This script is exclusive to only determining if a broadband audio link should be provided or not based on the visitor's preference. Also I'm providing some additional code to help with testing below...
Code: Select all
<?php
if (isset($_GET['audio'],$_COOKIE['audio']) && $_GET['audio']===0 || $_COOKIE['audio']==0) {?>
<span class="neutral">Hi-Fi Disabled</span>
<?php }
else if (isset($_GET['audio'],$_COOKIE['audio']) && $_GET['audio']===1 || $_COOKIE['audio']==1) {?>
<span class="neutral">Hi-Fi Disabled</span>
<? }
else if ($_GET['audio']===2 || !isset($_GET['audio']) && $_COOKIE['audio']==2) { ?>
<a class="icon music" href="javascript:if (location== top.location) {alert ('Audio Locked, Frame Unavailable!')}" onmousedown="if (location!= top.location) {parent.mplayer.location.href='../mplayer/jab-creations-2.0-01-hi.php';} else {return false;}" rel="mplayer" title="Play the high quality preview of this song.">Hi-Fi Play</a>
<?php } ?>Code: Select all
if ($_GET['audio'] == "0") {setcookie('audio','0',time()+2592000,'/');}
else if ($_GET['audio'] == "1") {setcookie('audio','1',time()+2592000,'/');}
else if ($_GET['audio'] == "2") {setcookie('audio','2',time()+2592000,'/');}