Video Streaming using PHP


I got this small code on 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=””&gt; ..> 

==> we put <embed src= ..>
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

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   


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 
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); 


About Uma Mahesh

A Creator/Equilizer. Creator/Equalizers are catalysts for positive, well-organized change. They never settle for the status quo. Instead, they see the opportunity for innovation in the processes that others have long taken for granted. They respect what's already operating, but they can't help but want to improve upon it. Their special combination provides innovation tempered with profound logic. They have incredible discernment. Should their efforts fail, they are unhesitating in accepting responsibility. They don't wallow in self-pity but rather see these missed attempts as critical steps on the path to success.
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: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s