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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

w

Connecting to %s