Jump to content

Extremely Challenging/Bizarre Problem


styx66

Recommended Posts

Posted this in the mysql help forums, but this might be php related... I'm just not sure.  Mod might want to delete one thats in a less appropriate forum. hehe.

 

Summary: A DELETE query interferes with Windows Media Player?

 

Background: I run a registration-required php/mysql site that serves .wma files.  Works great.  At one point, a member posted a link to one of my files on another web site, and people could download the file without registering/logging in. 

 

So I decided to use PHP to readfile($file) to logged in users only, and .htaccess the files directory.  Works like a charm.  Like so:

	header('Content-Type: audio/x-ms-wma');
header('Content-Disposition: attachment; filename="whateverfile.wma"');
header('Content-Transfer-Encoding: binary');
readfile($file);

 

Had to add the mime type to apache but no problem.

 

So now I've decided I'd like to stream files to people, instead of them having to download them fully first.  Since I don't run a windows media server, i do it the pseudo-stream method, by providing the user with a dynamically generated .asx (using php of course) that opens for them in their media player, and begins download/playing the file.

 

Works great, EXCEPT: i have to disable the .htaccess in order to allow media players to access the file, which I don't want to do.

 

So... I decided to try and implement the same system with streams as with downloads.  The obstacle there is that a media player cant exactly log in to my site, afaik.  So I decided to create a database table called 'stream'.  When the .asx is generated, a user ID, file ID, and random passkey are inserted into the stream table, and the link given in the .asx is a php script that is supposed to check the passkey corresponding to the user ID in the table, and if it matches, delete the entry completely, and readfile() the file corresponding to the file_id.

 

Struggled with this beast for hours and hours.  When the script includes/executes the DELETE FROM query, WMP will not play the file. 

 

I've tried different incarnations of the script, executing the query at different times, even trying some fancy redirects.  I even tried using an UPDATE query instead of DELETE, but again, WMP refuses.  Substituting with a SELECT query causes no problems.  Also tried closing and reopening the msyql connection to no avail.

 

If i simply comment out the query, WMP has no problems. 

 

As a test, i put the link within the .asx inside my browser and hit go, and it downloaded the file, even with the delete query intact.

 

So... What the heck? Nothing makes any sense to me here.  Any input (or alternative method) is greatly appreciated.

 

Here's the stream.php code:

<?php
session_start();
require_once ("./include/session_init.php");

mysql_connect($_SESSION['MYSQL_SERVER'],$_SESSION['MYSQL_LOGIN'],$_SESSION['MYSQL_PASS'])
                   or die("Unable to connect to SQL server");
    mysql_select_db($_SESSION['MYSQL_DB']) or die("Unable to select database");
    
$query1 = "SELECT pass FROM stream WHERE user_id = ".$_GET['user_id'];
    $result1 = mysql_query($query1) or die("Invalid query (login): " . mysql_error());
    $row = mysql_fetch_assoc($result1);
    $pass = $row['pass'];

$query2 = "DELETE FROM stream WHERE user_id = ".$_GET['user_id']." LIMIT 1"; 
$result2 = mysql_query($query2); or die("Invalid query (login): " . mysql_error());

$query = "SELECT path, name FROM files WHERE file_id = ".$_GET['file_id'];
$result = mysql_query($query) or die("Invalid query (login): " . mysql_error());
$row = mysql_fetch_assoc($result);
$file = $row['path'].$row['name'];

    if ($_GET['pass'] == $pass)
{
header('Content-Type: audio/x-ms-wma');
header('Content-Disposition: attachment; filename="'.$row['name'].'"');
header('Content-Transfer-Encoding: binary');
readfile($file);
//header("Location: stream_go.php?FILE=".$file);
}
else {
 exit;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/39414-extremely-challengingbizarre-problem/
Share on other sites

Yeah i had thought of that, i had it commented out at one point.

 

It is actually deleting the record from the database, so the query does execute properly.  And i think i mentioned, if i paste the link from the .asx (like, "http://www.mydomain.com/stream.php?user_id=1&pass=1571431264&file_id=99") directly into my browser, i can open/dl the file...

 

I just can't wrap my head around what the problem could be.  I have to assume its WMP-related but what exactly is WMP getting from my server without the delete query as opposed to with it?  Just doesn't make sense.

 

Perhaps i should just scrap this method and look for an alternative.  Its just so stupid! It should work!

Just noticed a key factor :D

 

$result2 = mysql_query($query2); or die("Invalid query (login): " . mysql_error());

 

Notice the semicolon after the mysql_query? Bad semicolon, bad!

 

heh well the reason for that was that i had a TON of commented out code from messing with it so much, i went through and quickly uncommented/removed stuff to clean it up to post here, so its not actually that way in the file, i had // 'd out the or die part.

 

So i gave up and switched to an IP-based verification.  When the .asx is generated, it records the user's IP, the stream.php verifies the IP thru $REMOTE_ADDR.  Simple enough lol.  (though i'm sure someone absolutely determined could break this if they knew that was the method i used.)

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.