howtothings.co.uk
Adding an MP3 in to a HTML file, using a PHP 404 redirect (Auto play and loop) - Printable Version

+- howtothings.co.uk (https://www.howtothings.co.uk)
+-- Forum: Computing (https://www.howtothings.co.uk/forumdisplay.php?fid=4)
+--- Forum: Website Development, Implementation and General Webmaster Support (https://www.howtothings.co.uk/forumdisplay.php?fid=9)
+--- Thread: Adding an MP3 in to a HTML file, using a PHP 404 redirect (Auto play and loop) (/showthread.php?tid=373)



Adding an MP3 in to a HTML file, using a PHP 404 redirect (Auto play and loop) - Mark - 25-09-2010



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