Jump to content

Javascript within PHP


hexcode

Recommended Posts

<html>
<head>
<script type=\"text/javascript\" src=\"swfobject.js\"></script>
</head>
<body>
        <script type=\"text/javascript\">
		var multiplayer = new SWFObject(\"player.swf?xml=config.xml&player_skin=skin.swf\", \"multiVideoPlayer\", \"361\", \"283\", \"7\", \"#FFFFFF\", true);
		multiplayer.write(\"flashcontent\");
	</script>
</body>
</html>

Hi,

 

Could anyone help make the above code run inside my PHP file?

When loaded, I just get a blank page and I know the paths to files are correct.

 

Thank you

Edited by hexcode
Link to comment
Share on other sites

<?php
if($user->data['is_registered'])
{
echo "<html>
<head>
<script type=\"text/javascript\" src=\"swfobject.js\"></script>
</head>
<body>
<script type=\"text/javascript\">
        var multiplayer = new SWFObject(\"player.swf?xml=config.xml&player_skin=skin.swf\", \"multiVideoPlayer\", \"361\", \"283\", \"7\", \"#FFFFFF\", true);
        multiplayer.write(\"flashcontent\");
    </script>
</body>
</html>";
}
else
{
echo '<html>
<head></head>
<body>Please login to access this page.</body>
</html>';
}
?>

Hi,

 

Above is a slimmed down version of the full file. How it works is if the user is logged in, it will display the Javascript section. If not, it will ask them to log in.

 

I used to call the the swf file a different way using "object" as seen below, but this is a complete different swf setup and I can not use the old call system.

<html>
<head>
<script type=\"text/javascript\">if (top.frames.length!=0) top.location=self.document.location;</script>
</head>
<body>
<object type=\"application/x-shockwave-flash\" data=\"player.swf\" width=\"325\" height=\"235\">
<param name=\"movie\" value=\"player.swf\"></object>
</body>
</html>
Edited by hexcode
Link to comment
Share on other sites

Try this....

<html>
<head>
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body>
<?php
	if($user->data['is_registered']){
		echo <<<EOT
			<script type="text/javascript">
				var multiplayer = new SWFObject("player.swf?xml=config.xml&player_skin=skin.swf", "multiVideoPlayer", "361", "283", "7", "#FFFFFF", true);
				multiplayer.write("flashcontent");
			</script>
EOT;
	}
    else{
    	echo "Please login to access this page!";
    }	
    
?>
</body>
</html>
Link to comment
Share on other sites

As indicated by chriscloyd's code - do not duplicated code. You apparently only want to change the content of the page and there is no need to replicate the creation of the HTML, HEAD and other tags. Use php to determine the dynamic content and "plug it in" to the template of the page. I would make one change to chriscloyd's code and determine the content BEFORE the output is started.

 

As for a blank page, did you view the HTML source of the page? I'm not very good with flash and don't know if the code you have would produce and output. I modified the above code to add some debugging logic so you can verify if the page is getting executed correctly.

 

 

<?php
 
$ouput = "Please login to access this page!";
$debug = "Condition is false";
if($user->data['is_registered'])
{
    $ouput = '<script type="text/javascript">
var multiplayer = new SWFObject("player.swf?xml=config.xml&player_skin=skin.swf", "multiVideoPlayer", "361", "283", "7", "#FFFFFF", true);
multiplayer.write("flashcontent");
</script>';
    $debug = "Condition is true";
}
    
?>
<html>
<head>
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body>
<?php echo $output; ?>
<br>
<?php echo $debug; ?>
</body>
</html>
Link to comment
Share on other sites

 

As indicated by chriscloyd's code - do not duplicated code. You apparently only want to change the content of the page and there is no need to replicate the creation of the HTML, HEAD and other tags. Use php to determine the dynamic content and "plug it in" to the template of the page. I would make one change to chriscloyd's code and determine the content BEFORE the output is started.

 

As for a blank page, did you view the HTML source of the page? I'm not very good with flash and don't know if the code you have would produce and output. I modified the above code to add some debugging logic so you can verify if the page is getting executed correctly.

<?php
 
$ouput = "Please login to access this page!";
$debug = "Condition is false";
if($user->data['is_registered'])
{
    $ouput = '<script type="text/javascript">
var multiplayer = new SWFObject("player.swf?xml=config.xml&player_skin=skin.swf", "multiVideoPlayer", "361", "283", "7", "#FFFFFF", true);
multiplayer.write("flashcontent");
</script>';
    $debug = "Condition is true";
}
    
?>
<html>
<head>
<script type="text/javascript" src="swfobject.js"></script>
</head>
<body>
<?php echo $output; ?>
<br>
<?php echo $debug; ?>
</body>
</html>

 

Yup, it works. False when logged out and True when logged in. I already knew the base script worked. The problem is the new way of calling this swf player.

 

Just so you can try this on your end, the script is here: http://www.tufat.com/script146.htm

Click the try it free link or use http://www.tufat.com/files_lgpl/script_146.zip

 

That way you can try the call the music player on your own server using my modified php.

 

I think the problem is this just the way this swf scrip is called. Because on my old music player the "object" based calling worked while the new way of calling this swf with javascript does not load right when in php.

        <script type=\"text/javascript\">
		var multiplayer = new SWFObject(\"player.swf?xml=config.xml&player_skin=skin.swf\", \"multiVideoPlayer\", \"361\", \"283\", \"7\", \"#FFFFFF\", true);
		multiplayer.write(\"flashcontent\");
	</script>
Edited by hexcode
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.