PHP and Flash [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

jts_01
Forum Newbie
Posts: 10
Joined: Fri Dec 23, 2005 10:21 pm

PHP and Flash [SOLVED]

Post by jts_01 »

I have a problem with a flash banner on top of my site that keeps reloading at every new page. So I made the page into two parts using php includes one part the header (where the flash is) and the other part into the page body. However, the flash still reloads. Any insight in how to keep the header from refreshing would be appreciated. Thanks.

This is the code that im using for the includes-

Code: Select all

<?php
$url=$_GET['url']; if (empty($url)) { $url='index'; } 
changelocation($url);
function changelocation($url) {
echo '<table width="766" border="0" align="center" cellpadding="0" cellspacing="0">';
echo '<tr>';
echo '<table width="766" border="0" align="center" cellpadding="0" cellspacing="0">';
echo '<tr>';
echo '<td height="0">';
switch ($url) 
{ 
case 'index': 	
include ('main.html'); 
break; 
case 'hosting':
include ('hosting.html');
break;
case 'servers':
include ('servers.html');
break;
case 'about':
include ('about.html');
break;
case 'support':
include ('support.html');
break;
case 'membersarea':
include ('membersarea.html');
break;
}
echo '</td></tr></table>';
}
?>
Last edited by jts_01 on Sun Dec 25, 2005 5:02 pm, edited 1 time in total.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Is the flash file actually re-downloading off the server, or is the movie just starting over?
jts_01
Forum Newbie
Posts: 10
Joined: Fri Dec 23, 2005 10:21 pm

Post by jts_01 »

I believe it's starting over or stored in the users cache.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

The flash movie will start over since you are changing the page it is contained in, the only solution I can think of is frames
User avatar
Trenchant
Forum Contributor
Posts: 291
Joined: Mon Nov 29, 2004 6:04 pm
Location: Web Dummy IS

Post by Trenchant »

Another solution could be using a session.

Code: Select all

<?php
if ($_SESSION['new_user'] == true) {
     // The user has seen the initial banner.   Don't show it again.
     SHOW BANNER
} else {
     // The user hasn't seen the initial banner.  Show it.
     SHOW INITIAL BANNER WITH INTRO OR WHATEVER

    // Set the session value so that the user doesn't see this banner view again
     $_SESSION['new_user'] = 'true';
}
That might be the solution you're looking for. The only downfall is that it requires two copies of your flash banner made. You could get the flash banner to check for a PHP value but that would be slower and use up more resources.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

PHP is server-side so you'll need a client-side solution to prevent a client from reloading a specific portion of the page.

eg.
-Using Frames
-AJAX
-Hidden divs & JavaScript
-Build it entirely in Flash
jts_01
Forum Newbie
Posts: 10
Joined: Fri Dec 23, 2005 10:21 pm

Post by jts_01 »

Another solution could be using a session.

PHP:
<?php
if ($_SESSION['new_user'] == true) {
// The user has seen the initial banner. Don't show it again.
SHOW BANNER
} else {
// The user hasn't seen the initial banner. Show it.
SHOW INITIAL BANNER WITH INTRO OR WHATEVER

// Set the session value so that the user doesn't see this banner view again
$_SESSION['new_user'] = 'true';
}


That might be the solution you're looking for. The only downfall is that it requires two copies of your flash banner made. You could get the flash banner to check for a PHP value but that would be slower and use up more resources.
Yea this more like what I'm looking for. I've created the two files but I'm kind of confused about how I should put my flash in where you say "show banner." Some example of this would really help. Thanks so far.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Code: Select all

if ($_SESSION['new_user'] == true) {
// The user has seen the initial banner. Don't show it again.
?>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="550" height="450">
	<param name="movie" value="movie.swf" />
	<param name="quality" value="high" />
	<embed src="movie.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="450"></embed>
</object>
<?
} else {
just exit php and put the html in like that
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

use isset() as well to avoid getting notice errors.

Code: Select all

if ((isset($_SESSION['new_user'])) && ($_SESSION['visited'] === true)) {
    //user has visited site with this session..
} else {
   //user has not
}
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

http://uk.php.net/session
Have a read on how to use sessions.

And please use PHP tags when posting php code.
jts_01
Forum Newbie
Posts: 10
Joined: Fri Dec 23, 2005 10:21 pm

Post by jts_01 »

It doesn't seem to work. After I refresh the browswer it only displays the cougar_1.swf. No erros are displayed nor have I found any in the log.


This is the code I have now-

Code: Select all

<?php 
if ((isset($_SESSION['new_user'])) && ($_SESSION['visited'] === true)) { 
     // The user has seen the initial banner.   Don't show it again.  
	 ?>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="510" height="205">
              <param name="movie" value="flash/cougar1_re.swf">
              <param name="quality" value="high">
              <embed src="flash/cougar1_re.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="510" height="205"></embed>
          </object>
		  <?php
} else { 
?>	
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="510" height="205">
              <param name="movie" value="flash/cougar1_.swf">
              <param name="quality" value="high">
              <embed src="flash/cougar1_.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="510" height="205"></embed>
          </object>
		  <?php
    // Set the session value so that the user doesn't see this banner view again 
     $_SESSION['new_user'] = 'true';  
} 
?>
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

looks like you forgot to call

session_start() at the top of your script...

and this line:

Code: Select all

$_SESSION['new_user'] = 'true';
should be

Code: Select all

$_SESSION['new_user'] = true;
especially since you're using equivalent to operator (===) instead of equal to (==)
jts_01
Forum Newbie
Posts: 10
Joined: Fri Dec 23, 2005 10:21 pm

Post by jts_01 »

Sorry to post about this so much but now I getting

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/trance/public_html/flashtest.php:9) in /home/trance/public_html/flashtest.php on line 128

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/trance/public_html/flashtest.php:9) in /home/trance/public_html/flashtest.php on line 128




Code: Select all

<?php 
		  session_start();
if ((isset($_SESSION['new_user'])) && ($_SESSION['visited'] === true)) { 
     // The user has seen the initial banner.   Don't show it again.  
	 ?>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="510" height="205">
              <param name="movie" value="flash/cougar1_re.swf">
              <param name="quality" value="high">
              <embed src="flash/cougar1_re.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="510" height="205"></embed>
          </object>
		  <?php
} else { 
?>	
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="510" height="205">
              <param name="movie" value="flash/cougar1_.swf">
              <param name="quality" value="high">
              <embed src="flash/cougar1_.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="510" height="205"></embed>
          </object>
		  <?php
    // Set the session value so that the user doesn't see this banner view again 
     $_SESSION['new_user'] = true;  
} 
?>
jts_01
Forum Newbie
Posts: 10
Joined: Fri Dec 23, 2005 10:21 pm

Post by jts_01 »

Sorry to post about this so much but now I getting

Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/trance/public_html/flashtest.php:9) in /home/trance/public_html/flashtest.php on line 128

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/trance/public_html/flashtest.php:9) in /home/trance/public_html/flashtest.php on line 128


line 128 being session_start();




Code: Select all

<?php 
		  session_start();
if ((isset($_SESSION['new_user'])) && ($_SESSION['visited'] === true)) { 
     // The user has seen the initial banner.   Don't show it again.  
	 ?>
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="510" height="205">
              <param name="movie" value="flash/cougar1_re.swf">
              <param name="quality" value="high">
              <embed src="flash/cougar1_re.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="510" height="205"></embed>
          </object>
		  <?php
} else { 
?>	
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="510" height="205">
              <param name="movie" value="flash/cougar1_.swf">
              <param name="quality" value="high">
              <embed src="flash/cougar1_.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="510" height="205"></embed>
          </object>
		  <?php
    // Set the session value so that the user doesn't see this banner view again 
     $_SESSION['new_user'] = true;  
} 
?>
Post Reply