Current location: Hot Scripts Forums » Programming Languages » PHP » Toggle Flash On/Off


Toggle Flash On/Off

Reply
  #1 (permalink)  
Old 11-22-04, 02:41 PM
wicichris wicichris is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Toggle Flash On/Off

I've seen sites enable the user to toggle flash enabled versions of their pages on and off. I know this is acomplished by PHP, but I'm not quite sure how to script it or where I can find a script like that.

I have browsed w3schools.com and found this simple switch example:

<?php
switch (2)
{
case 1:
echo "Number 1";
break;
case 2:
echo "Number 2";
break;
case 3:
echo "Number 3";
break;
default:
echo "No number between 1 and 3";
}
?>

If I were to use this in the areas where I plan on injecting Flash or non-Flash elements, how do I feed HTML code into those cases? And how do I get it to toggle?

You can see examples of what I mean at http://www.broadcom.com/ and at http://www.***-kickin.com/

On Broadcom, just click "Turn Flash On" and for ***-Kickin, click the "Turn Flash Off" tab at the bottom. That's the toggle I'm trying to accomplish.
Reply With Quote
  #2 (permalink)  
Old 11-22-04, 04:43 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
Ok so you have a flash header (flashheader.swf) and an image header (imgheader.gif) and you want to turn flash on or off (off will just display the image). So on the homepage and every page you want flash or image you would put at the top of the page:

PHP Code:

<?php

//if cookie flash is not set then make flash on by default
if (!isset($_COOKIE[flash])) {
$flash "on";
}
//otherwise retrieve flash on or off from the cookie
else {
$flash $_COOKIE['flash'];
}
?>
So now here is where you put the code in the html where you want flash to display:

PHP Code:

<?php

//if flash is on echo the flash html code
if ($flash == "on") {
echo 
'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0">
<param name="movie" value="flashheader.swf">
<param name="quality" value="high">
<embed src="flashheader.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash">
</embed>
</object>'
;
}

//otherwise echo the image html code
else {
echo 
'<img src="imgheader.gif" border="0">';
}
?>
Ok now we have done this we need to set flash on or off in the following url:

Flash: flash.php?switch=on
Image: flash.php?switch=off

So in your flash you would create a link to go to 'flash.php?switch=on' called 'Turn Flash Off' and in your image html you would create a link to 'flash.php?switch=off' called 'Turn Flash On'.

flash.php:

PHP Code:

<?php


//set cookie on or off
setcookie ('flash'$_GET[switch], time()+31536000);

//then redirect them back home
header("Location: index.php");
?>
The end
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.

Last edited by FiRe; 11-22-04 at 04:48 PM.
Reply With Quote
  #3 (permalink)  
Old 11-22-04, 05:32 PM
wicichris wicichris is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Hey Fire,

Thanks for the bang up job on your reply. It answers a lot of my questions, however, after setting up flash.php and linking to it, once I click the href for "flash.php?switch=on", I get the following:

Quote:
Parse error: syntax error, unexpected T_SWITCH, expecting ']' in flash.php on line 4
Line 4 in this case is:

PHP Code:

setcookie ('flash'$_GET[switch], time()+31536000); 

Any ideas?
Reply With Quote
  #4 (permalink)  
Old 11-23-04, 06:42 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
Try:

$cookie = $_GET['switch'];
setcookie ('flash', $cookie, time()+31536000);
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #5 (permalink)  
Old 11-23-04, 12:14 PM
wicichris wicichris is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
FiRe,

That worked! You're a God ****ed genius. Thanks for helping a newbie along.

Now for my final question, is there any way to redirect them back to the page they came from in flash.php, rather than throwing them back to index.php everytime they turn flash on or off?

Last edited by wicichris; 11-23-04 at 12:17 PM.
Reply With Quote
  #6 (permalink)  
Old 11-23-04, 01:55 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
yeh instead of:

header("Location: index.php");

try:

header("Location: $_SERVER[HTTP_REFERER]");

glad it all worked out, took me a while to write
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #7 (permalink)  
Old 11-23-04, 03:00 PM
wicichris wicichris is offline
Newbie Coder
 
Join Date: Nov 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Outstanding! It works. Fire, you truly are a life saver. My fullest thanks to you for spelling it all out for me.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CamDate - Adult, Dating & Community Orientated Flash Audio / Video Chat Software CamDate.Biz General Advertisements 1 09-17-07 09:21 AM
Flash Submission and indexing Script DestinyZero Script Requests 2 10-17-04 10:51 AM
Php with flash or without tables ? EraseR PHP 0 06-26-04 07:36 AM
showing flash or .gif..please help webon Script Requests 0 03-25-04 04:28 PM
javascript object hidden by flash object morlack JavaScript 1 03-09-04 05:36 AM


All times are GMT -5. The time now is 05:16 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.