So I have this site that generates xml playlists for a user and plays them in a JW Flash player. I'd like it to behave such that, when a user navigates away from the player page (like closes the window, or goes to another site) or when they click the back button on their browser that the playlist is deleted. So there's 2 pages: 1) A set up page with checkboxes that dictates what kind of playlist will be generated and 2) the player page. On the first page, I have a method called init() which clears all the checkboxes and tries to delete any playlist that exists. On the second page, I try to delete the playlist if they navigate away. Here's the code for init() :
Code: Select all
function init() {
//This variable maps a supergenre to an array of its subgenres
superToSubs = new Array();
var str = "<?php echo $genreString; ?>";
var superToSubString = str.split("!!");
for (var i = 0; i < superToSubString.length; i++) {
var superSubSplit = superToSubString[i].split("$$");
//position 0 has the super, and then position one has SUB**SUB**SUB**
var subs = null;
if (superSubSplit.length > 1)
subs = superSubSplit[1].split("**");
superToSubs[superSubSplit[0]] = subs;
}
var elements = document.getElementsByTagName('*');
for (var i = 0; i < elements.length; i++) {
if (elements[i].type == 'checkbox')
elements[i].checked = false;
}
document.getElementById('random').checked = true;
var dummyimage = new Image();
dummyimage.src = "deletePlaylist.php";
}
Code: Select all
<?php
$fh ="playlist.xml";
unlink($fh);
?>
Code: Select all
header('Expires', 'Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified', gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control', 'no-store, no-cache, must-revalidate');
header('Cache-Control', 'post-check=0, pre-check=0');
header('Pragma', 'no-cache');
Code: Select all
header('Location: sikhpod.html');
Code: Select all
function closeBrowser() {
var dummyimage = new Image();
dummyimage.src = "deletePlaylist.php";
//alert("HI!");
}
</script>
</head>
<body onload='showlist(300);' onunload='closeBrowser()' onbeforeunload='closeBrowser()'>
I figured this would be the best place to post to find out about the best way to redirect in php...can anybody offer some advice for a php newbie? I'd really appreciate it.
Thanks,
Mark