• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding an MP3 in to a HTML file, using a PHP 404 redirect (Auto play and loop)
#1
Music 


Adding an MP3 in to a HTML file

How to add an MP3 in to a HTML file, optionally using htaccess and a PHP 404 redirect with auto play and looping features.

Why would you want to do this, and how does it work?

Firstly, The 404 or Not Found error message is a HTTP standard response code indicating that the client was able to communicate with the server, but the server could not find what was requested. eg. You go to your website and /webpage.html and if the file webpage.html isn't on the server, it'll just give you a 404 error page instead.

If you just want to make a simple web page with an MP3 on it, you can use this:

[code=html]
<embed src="songname.mp3" autostart="true" hidden="true" loop="true"></embed>
[/code]

You can also play with the values, such as loop and hidden.


Optional fancy extras:


.htaccess file

Code:
ErrorDocument 404 /error.php


error.php file

[code=php]
<?php

$status = $_SERVER['REDIRECT_STATUS'];
$codes = array(
404 => header('Location:http://mcompute.co.uk/error404.html')
);

$title = $codes[$status][0];
$message = $codes[$status][1];
if ($title == false || strlen($status) != 3) {
$message = 'Please supply a valid status code.';
}

echo '<p><h1>' . $title . '</h1></p>' .
'<p>' . $message . '</p>';

?>
[/code]

Save the three files and upload them all to the root of your web server, (public_html)

Then browse to a 404 page, such as http://yoursite.com/nopagehere.html


Further reading of using .htaccess and PHP

http://mcompute.co.uk/showthread.php?tid=366

  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [TUT] Adding a Facebook share button to your forum Mark 1 16,180 14-05-2011, 01:12 AM
Last Post: Mark
  [TUT] Adding a twitter button to your forum Mark 0 9,827 04-12-2010, 06:48 PM
Last Post: Mark
  Adding a note on the registration form Mark 0 4,832 19-10-2010, 12:44 AM
Last Post: Mark
  Basic HTML coding Mark 2 10,020 16-06-2010, 06:19 AM
Last Post: Special Chris

Forum Jump: