Jump to content

PHP newbie help: player.php?id=x


!MNc99

Recommended Posts

Hi there;

Before we begin I know how annoying it is to have someone coming and ask someone else do all the work for them; I'm pretty much a complete PHP virgin and the best way for me to learn code is essentially to steal other people's and work from it. Not a good technique, I know. Regardless- if you do have a solution, bless you, but please, explain any technical language because I suck. Cheers!

 

I have a very simply website showcasing a few flash animations. I've designed a page with image wrappers and my intention is to place a movie inside it loaded by an outside variable which will be placed inbetween the images so it looks like the animation is coming from inside a TV set.

 

The basis for the address would be http://www.example.com/animations/player.php?id=1

 

With player.php being the page designed with the wrapper and 1 being an ID for some movie.

 

As of yet the only thing I can say I actually have materialised is the wrapper page because I'm more designer than coder. So- from the ground up, how do I go about doing this?

 

Any replies gratefully received. Even ones regarding my mother.

 

!MNc99

Link to comment
Share on other sites

I'm guessing you want to do this without a database or anything. I think what you're looking for is something like this...

 

<?php
/**
* This array is setting the animation that you want to allow
* We will use the key to reference them, so passing the key in the url
* player.php?id=animation1
*/
$allowedAnimations = array(
"animation1" => "the-animation-1-src.avi",
"animation2" => "the-animation-2-src.wmv",
"animation3" => "the-animation-3-src.mpeg"
);

/**
* Here we'll check if id is set in the url
* If it is we'll check it against the array
* If it's not in the array we'll re-direct to the home page
*/
if(isset($_GET['id'])) {
if(array_key_exists($_GET['id'], $allwoedAnimations)) {
	//Found an animation, lets get the source
	$animation = $allowedAnimations[$_GET['id']];
} else {
	//Array key doesn't exist, get him outta here
	header("Location: /index.php");
	exit;
}
} else {
header("Location: /index.php");
exit;
}

/**
* Next you need to put the src in the relevant place in your embed code
* I'll leave that up to you (though here is a little example)
*/
$animationScript = <<<EOD
<OBJECT id="VIDEO" width="320" height="240" 
style="position:absolute; left:0;top:0;"
CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6"
type="application/x-oleobject">

<PARAM NAME="URL" VALUE="$animation">
<PARAM NAME="SendPlayStateChangeEvents" VALUE="True">
<PARAM NAME="AutoStart" VALUE="True">
<PARAM name="uiMode" value="none">
<PARAM name="PlayCount" value="9999">
</OBJECT>
EOD;

 

After that you just need to echo $animationScript in the correct place on your page. None of this is tested but should give you a good start!

Link to comment
Share on other sites

That's fantastic, gevans. Many thanks.

One question, though- do both bits of code go on the same page? Where are they meant to be, and should both be in player.php in the <head> tag or something?

 

I understand I'm meant to use an embed $animationScript tag at some point inbetween my wrapper images- that seems simple enough, I'll google it later- but where would the code that is referring to go?

 

Other than that, it's solid. Thanks!

Link to comment
Share on other sites

Good christ, it works! You are the man. Thank you so much.

 

There is one minor thing I have issue with; I wonder if you could lend a hand?

 

http://mnc99.com/animation/player.php?id=example

 

This is the player, working like a charm. Notice, however, the two tiny gaps on both sides of the script. Dreamweaver seems to hate scrunching things up and will always endeavour to place minute gaps in, especially where they break the look of things. Is there anything I can do to axe them? (I'm using the Opera browser.)

 

Thanks for all your help!

Link to comment
Share on other sites

Sorry for the double-post. It won't let me edit further.

-I have also just noticed that the page seems to want to work in Opera exclusively. In Internet Explorer it just loads a white screen with a gap at the BOTTOM as well (although all these annoying gaps dissipate if I use 'compatibility view') and in Firefox it refuses to load the SWF at all. Could someone else try these out and see if it isn't just a problem on my end?

http://mnc99.com/animation/player.php?id=example

Link to comment
Share on other sites

Ok, here's where I am at the moment.

 

<?php
{
$animationScript = <<<EOD
<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="550" height="400">
    <param name="URL" value="$animation">
    <param name="quality" value="high">
    <embed src="$animation" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="550" height="400"></embed></object>
EOD;
echo ($animationScript);
}
?>

 

This results in an SWF animation that displays fine in Opera and Firefox. Internet Explorer, however, displays only a white box bearing the dreaded 'Movie not loaded..' legend.

 

Could anyone take a look at the code and see if there isn't some terrible mistake I've made? I hate asking for help, it seems so lazy on my part, but I'm at my wit's end on this one.

 

Many thanks.

Link to comment
Share on other sites

gevans, see how the code you originally gave me has deviated in my next post. This is as far as I have managed to come and it works, but only on two browsers. Just 'use the right code' isn't much help in my current position.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.