Jump to content

How to use php code in html page. This may be simple question to many please hel


dinold02

Recommended Posts

Hi, I am new to php scripting.

 

I just learned about this "Generating One-Time URLs with PHP"

Please visit this link for more info http://www.onlamp.com/pub/a/php/2002...time_URLs.html

 

My question is that How Could I use this code that generates this special link to the file and use it into object player.

 

I think this may be confusing to many.

 

This is the code to embedded a MS Media Player.

 

Quote:

<embed id="wmplayer" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="PUT THE VIDEO LINK HERE" width="419" height="350" type="application/x-mplayer2" volume="0" showtracker="0" showpositioncontrols="0" showgotobar="0" showdisplay="0" showaudiocontrols="1" showcontrols="1" sendplaystatechangeevents="-1" sendmousemoveevents="0" sendmouseclickevents="0" sendkeyboardevents="0" senderrorevents="-1" sendwarningevents="-1" sendopenstatechangeevents="-1" enabletracker="-1" enablefullscreencontrols="1" enablepositioncontrols="-1" enablecontextmenu="0" enabled="-1" displaysize="4" displaymode="0" allowchangedisplaysize="-1" allowscan="-1" autosize="-1" autostart="1" allowfullscreen="true" bgcolor="#000000"><noembed></noembed>

And This PHP code generates Url that can be accessed one single time.

 

Quote:

<?

/*

* generate_url.php

*

* Script for generating URLs that can be accessed one single time.

*

*/

 

/* Generate a unique token: */

$token = md5(uniqid(rand(),1));

 

/* This file is used for storing tokens. One token per line. */

$file = "/tmp/urls.txt";

if( !($fd = fopen($file,"a")) )

die("Could not open $file!");

 

if( !(flock($fd,LOCK_EX)) )

die("Could not aquire exclusive lock on $file!");

 

if( !(fwrite($fd,$token."\n")) )

die("Could not write to $file!");

 

if( !(flock($fd,LOCK_UN)) )

die("Could not release lock on $file!");

 

if( !(fclose($fd)) )

die("Could not close file pointer for $file!");

 

/* Parse out the current working directory for this script. */

$cwd = substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],"/"));

 

/* Report the one-time URL to the user: */

print "Use this URL to download the secret file:<br><br>\n";

print "<a href='http://".$_SERVER['HTTP_HOST'].

"$cwd/get_file.php?q=$token'>\n";

print "http://".$_SERVER['HTTP_HOST']."/get_file.php?q=$token</a>\n";

 

?>

What I am trying to do is that I want to use this code with the embedded Media Player. On the embedded media player where it asked for the source "src="PUT THE VIDEO LINK HERE" I want to use the "http://".$_SERVER['HTTP_HOST']."/get_file.php?q=$token" link that is being generated by the script to it.

 

So This will make it hard for people to leech my video. But how do i use both scripts together and make this happen.

 

So basically I want the embedded media player source to read this link "http://".$_SERVER['HTTP_HOST']."/get_file.php?q=$token" to play. How do i make it work out.

 

So on the media player it should open the generated link and play.

im pretty sure i understand your intentions.

here is my interpretation:

<?
/*
* generate_url.php
*
* Script for generating URLs that can be accessed one single time.
*
*/

/* Generate a unique token: */
$token = md5(uniqid(rand(),1));

/* This file is used for storing tokens. One token per line. */
$file = "/tmp/urls.txt";
if( !($fd = fopen($file,"a")) )
die("Could not open $file!");

if( !(flock($fd,LOCK_EX)) )
die("Could not aquire exclusive lock on $file!");

if( !(fwrite($fd,$token."\n")) )
die("Could not write to $file!");

if( !(flock($fd,LOCK_UN)) )
die("Could not release lock on $file!");

if( !(fclose($fd)) )
die("Could not close file pointer for $file!");

/* Parse out the current working directory for this script. */
$cwd = substr($_SERVER['PHP_SELF'],0,strrpos($_SERVER['PHP_SELF'],"/"));

/* Report the one-time URL to the user: */
print "Use this URL to download the secret file:<br><br>\n";
print "<a href='http://".$_SERVER['HTTP_HOST'].
"$cwd/get_file.php?q=$token'>\n";
$thelink = "http://".$_SERVER['HTTP_HOST']."/get_file.php?q=$token</a>\n"; ### THIS IS AN ESSENTIAL CHANGE.
print <<<HTML
<embed id="wmplayer" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" src="$thelink" width="419" height="350" type="application/x-mplayer2" volume="0" showtracker="0" showpositioncontrols="0" showgotobar="0" showdisplay="0" showaudiocontrols="1" showcontrols="1" sendplaystatechangeevents="-1" sendmousemoveevents="0" sendmouseclickevents="0" sendkeyboardevents="0" senderrorevents="-1" sendwarningevents="-1" sendopenstatechangeevents="-1" enabletracker="-1" enablefullscreencontrols="1" enablepositioncontrols="-1" enablecontextmenu="0" enabled="-1" displaysize="4" displaymode="0" allowchangedisplaysize="-1" allowscan="-1" autosize="-1" autostart="1" allowfullscreen="true" bgcolor="#000000"><noembed></noembed>
HTML;
?>

 

basically what the <<<HTML does is it basically treats whatever is after that particular line as simple HTML code; however, you can ordinairily include variables as you would in php as well.  the HTML; basically tells php that it can stop treating the lines as html from then on.  You could even change the <<<HTML to whatever you want even <<<PHPFREAKS as long as you end the HTML processicing as well with the same name.

heres an example.

print <<<PHPFREAKS
<html>
<head>
<title> Media Player</title>
</head>
PHPFREAKS;

the script should work.  I hope my explanation helps you out as well. 

best of luck.

 

Thank you for your explanation. You understood my question well.

 

But now the problem I am getting is that the file wont play in the media player. What may be the problem?

 

Everything works fine, but the windows media player is not reading/playing the secret link.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.