We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Help with redirect type thing

I'm thinking of hosting a name that tune type game.

I don't know anything about PHP or even if it's the languge to use, but I'm hoping someone
might put me straight on that matter too.

Here is an outline of my needs/scenario.
I post a link to a song.mp3 I have uploaded to my host, the user has to guess the song and artist.
The problem is, as I'm sure most here will have immediately envisioned is the link to the song title
will be visible to anyone with some knowledge of how this sort of thing works.
I could change the title and meta data of the file, but that seems overkill.
I want to make a link to say Guess.mp3, but when that link is clicked it serves up an entirely different
Song.mp3 which is determined by a php script which cannot be seen or found without a fair bit of jiggery pokery.

I hope you follow what I mean and can advise if such a thing is even possible.
My hopes are that the link can be posted not on my own website, but for instance here at daniweb.
Any advice or suggestions of other methods are very welcome and much appreciated.

4
Contributors
24
Replies
21 Hours
Discussion Span
4 Months Ago
Last Updated
26
Views
Suzie999
Posting Whiz
316 posts since Jul 2010
Reputation Points: 49
Solved Threads: 14
Skill Endorsements: 0

You can point the audio to a PHP file (guess.php). It can return anything you want. If you set the right headers it can return an audio file too.

pritaeas
Posting Prodigy
Moderator
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

Any pinters as to how to do that?
If I put http://www.domian.com/guess.php in [media][/media] tags it just shows the url.

Suzie999
Posting Whiz
316 posts since Jul 2010
Reputation Points: 49
Solved Threads: 14
Skill Endorsements: 0
<audio controls autoplay>
    <source src="guess.php" type="audio/mpeg" />
    Your browser does not support the audio element.
</audio>

Then your guess.php has to read and return an mp3 file with the right headers.

pritaeas
Posting Prodigy
Moderator
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

Thanks for your time.

I have this in my guess.php file

//http://www.longtailvideo.com/support/forums/jw-player/setup-issues-and-embedding/3819/serving-a-mp3-file-with-php/

<?php
$fc = file_get_contents("NewMp3.mp3");
$size = filesize("NewMp3.mp3");
header('Content-type: audio/mpeg');
header('Content-length: ' . $size);
header('Content-Disposition: filename=NewMp3.mp3');
header('X-Pad: avoid browser bug');
Header('Cache-Control: no-cache');
echo $fc;
?>

If I navigate to the page http://www.domian.com/guess.php then a media player shows and the song plays. But I need the same to happen withing media tags on another website/forum.

Suzie999
Posting Whiz
316 posts since Jul 2010
Reputation Points: 49
Solved Threads: 14
Skill Endorsements: 0

I can't try right now, but any media method you use that accepts an url, should also accept your php script.

pritaeas
Posting Prodigy
Moderator
9,265 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,456
Skill Endorsements: 86

Hi Suzie99,

Can you add the content transfer encoding field and tell it's binary.
Content-transfer-encoding: binary
header('Content-transfer-encoding: binary')
Let me know what happened.

gon1387
Posting Whiz in Training
233 posts since Jan 2011
Reputation Points: 32
Solved Threads: 37
Skill Endorsements: 3

Hi gon1387, Thank you for reply, unfortunately there is no change.
Does it matter the order of header values?

Suzie999
Posting Whiz
316 posts since Jul 2010
Reputation Points: 49
Solved Threads: 14
Skill Endorsements: 0

No actually, unless you put the contents on top. LOL :D
Anyway joking asside. I've seen this one, I think it's the content type.
Q&A

Anyway, I;ve checked your script, you got a capitalized header func:

me=NewMp3.mp3');
header('X-Pad: avoid browser bug');
Header('Cache-Control: no-cache'); \\make the 'H' lower-case
gon1387
Posting Whiz in Training
233 posts since Jan 2011
Reputation Points: 32
Solved Threads: 37
Skill Endorsements: 3

I noticed that earlier and changed it, no luck :(
(edit)It does not seem to matter, I just tried them all capitalised, without change.

Suzie999
Posting Whiz
316 posts since Jul 2010
Reputation Points: 49
Solved Threads: 14
Skill Endorsements: 0

I was checking on the different encoding for MP3 and content-types. Any luck with the mime types in their solution?

gon1387
Posting Whiz in Training
233 posts since Jan 2011
Reputation Points: 32
Solved Threads: 37
Skill Endorsements: 3

Make it all small-case. PHP Header Function

gon1387
Posting Whiz in Training
233 posts since Jan 2011
Reputation Points: 32
Solved Threads: 37
Skill Endorsements: 3

Hi, I tried without success.
I also read in that article that nothing should precede header, so had to remove filesize
Code now looks like this, but still no good.

<?php
header('Content-type: audio/mpeg');
header('Content-Disposition: filename=NewMp3.mp3');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
header('Content-transfer-encoding: binary');
$fc = file_get_contents("NewMp3.mp3");
echo $fc;
?>
Suzie999
Posting Whiz
316 posts since Jul 2010
Reputation Points: 49
Solved Threads: 14
Skill Endorsements: 0

Actually, this method might not be very good, because if I navigate to the php page in browser and view source, the meta data is the first thing to see at the top with artist and title.

:(

Suzie999
Posting Whiz
316 posts since Jul 2010
Reputation Points: 49
Solved Threads: 14
Skill Endorsements: 0

What it's trying to say with "No output before the header" is there should be data to be output in the stream befor ethe header. When the HTML tag was included above, and before the '<?php' it already send a set of character to the output stream, which is the "<html>".

So the reason behind this is when you send the out put using the HTTP protocol(not in the context of PHP) it would look like this:

<html>
Location: http://www.example.com/
... other http fields ...

Which means, if read by the reciever is a malformed HTTP. Another way of expressing the sample in the PHP Manual is this:

<?php
echo "<html>";
/* This will give an error. Note the output
 * above, which is before the header() call */
header('Location: http://www.example.com/');
?>

So what you did earlier is right. You have to put the length especially if it's a get request, so the reciever, which is the browser would know when to stop listening for incoming data.

Anyhow, here's the sample code from SO, using your code:

<?php
$fc = file_get_contents("NewMp3.mp3");
$size = filesize("NewMp3.mp3");
header("Content-Transfer-Encoding: binary");
header('Content-type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3');
header('Content-length: ' . $size);
header('Content-Disposition: filename="NewMp3.mp3"');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');

echo $fc;

Let's hope this one works :D

gon1387
Posting Whiz in Training
233 posts since Jan 2011
Reputation Points: 32
Solved Threads: 37
Skill Endorsements: 3

Anyway, it's working on my end. How 'bout yours?

gon1387
Posting Whiz in Training
233 posts since Jan 2011
Reputation Points: 32
Solved Threads: 37
Skill Endorsements: 3

Nope, unless I'm doing something wrong.
I still get the link to it, and also, it does not try to play, and rather wants to download, and my browser dialog opens for me to choose a location.

I have just the php code, with no html at all on the page.

Suzie999
Posting Whiz
316 posts since Jul 2010
Reputation Points: 49
Solved Threads: 14
Skill Endorsements: 0

One question though, if you access in your browser.
yourdomain.com/mp3.php

does it download the right mp3 file you specified in your php file?

gon1387
Posting Whiz in Training
233 posts since Jan 2011
Reputation Points: 32
Solved Threads: 37
Skill Endorsements: 3

If you can download the right MP3 file. Then, create an HTML file http://www.w3schools.com/html/html_sounds.asp
CHeck if it plays on your end. be sure to reference the src which is yourdomain.com/mp3.php in the embed tag.

gon1387
Posting Whiz in Training
233 posts since Jan 2011
Reputation Points: 32
Solved Threads: 37
Skill Endorsements: 3

Yes, and plays fine with all meta data in tact.
I really do appreciate the time you have put into your generous assistance.
I'm beginning to think I might as well just remove meta data, and rename files, just seems too much.

Suzie999
Posting Whiz
316 posts since Jul 2010
Reputation Points: 49
Solved Threads: 14
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
 
© 2013 DaniWeb® LLC
Page rendered in 0.1434 seconds using 2.75MB