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 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: Logo

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