Video Streaming using PHP

Hi,

I got this small code on http://devshed.com where in i can hide my mediafile url via php. Instead of providing the direct media link, i will obscure the link with php

Instead of <embed src=”http://myworld.com/video/fun.mpg”&gt; ..> 

==> we put <embed src=http://myworld.com/streamvid.php?id=abcZshdiyX23ad ..>
In mysql database we maintain a table having pair (id, realURL).

steamvid.php will take id and fetch realURL and sends the data.

streamvid.php code

<?php>
if (! preg_match('/^[-a-z.-@,\'\s]*$/i',$_GET['ID'])) {
   die('Invalid name proved, the name may only contain a-z, A-Z, 0-9, "-", "_" and spaces.');
} else   

       $empty=strlen($_GET['ID']);

if ($empty==0) {
       die('The text field cannot be empty'); 
} 
else {    //the input data is clean, retrieve text data input    
     $ID = $_GET['ID']; 
} //Connect to MySQL database after sanitizing the data 
$username = "**********"; 
$password = "**********"; 
$hostname = "**********"; 
$database = "**********"; 
$dbhandle = mysql_connect($hostname, $username, $password)  or die("Unable to connect to MySQL"); 
//select a database to work with 
$selected = mysql_select_db($database,$dbhandle)   or die("Could not select $database"); 
//Escape variables for use in MySQL 
$ID = mysql_real_escape_string(stripslashes($ID)); 
// sending query 
$result = mysql_query("SELECT `realurl` FROM `videostreaming` WHERE `id`='$ID'") or die(mysql_error()); 
// store the record of the "example" table into $row 
$row = mysql_fetch_array( $result ) or die("Invalid query: " . mysql_error()); 
// Print out the contents of the entry 
$direction = $row['realurl']; 
//close the connection 
$path='http://'.$direction; 
header('Content-type: video/mpeg'); 
header('Content-Length: '.filesize($path)); 
// provide file size 
header("Expires: -1"); 
header("Cache-Control: no-store, no-cache, must-revalidate"); 
header("Cache-Control: post-check=0, pre-check=0", false); 

readfile($path); 
mysql_close($dbhandle);
</php>
Advertisements

About wikihead

A Seeker. Information Security Professional, Pursuing Life with Ayurveda.
This entry was posted in Articles, Web Designing and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s