CNC

Say It!

Another Free PHP Source Code Example!

This is an example PHP Script to show how “GET” is used in a real life situation, opposed to “POST” like in this example: http://whatisacnc.com/pages/progphp.php

Below find PHP Source Code that allows a visitor to click on a Link that in turn plays a “.wav” format audio file, this code is tested and working on this very website.

Test "Say It!". Just copy and past it into a Text Editor like “Context” then save the file as “index.php”. After that make a “.wav” file and save it in the same directory, this file should be named “main.wav”.

To change the file names from “index.php” or “main.wav” just change the names in the code below.

<?php

function soundm(){

if (isset($_GET['wav'])) {

$audiofile = "main.wav";

echo '<EMBED SRC="'.$audiofile.'" HIDDEN="TRUE" AUTOSTART="TRUE"></EMBED>';

}

}

soundm();

?>

<a href='index.php?wav=true'>Say It!</a>

How It Works!

To start we tell the PHP Compiler (installed with your XAMPP or Service-Provider) that we are in fact using PHP for the next little bit, we do that by producing the following:

<?php

?>

Now we make a “Function”, a function will run each time we call it! We now have this:

function soundm(){ }

<?php function soundm(){ }?>

Within the function we code something, in this case we check to see if the Link was clicked:

if (isset($_GET['wav'])) { }

<?php function soundm(){ if (isset($_GET['wav'])) { } }?>

If the link was clicked using the “GET” function, we then ask the users computer to start an Audio-Player plug in to play the .wav file using HTML (the Web Browser Compiler, E.g. Chrome | Firefox | Safari ), the “echo” statement is used because we have a variable within the HTML, in this case called $audiofile and this variable needs to be defined then called within the same <?php ?> section.

$audiofile = "main.wav";

echo '<EMBED SRC="'.$audiofile.'" HIDDEN="TRUE" AUTOSTART="TRUE"></EMBED>';

<?php function soundm(){ if (isset($_GET['wav'])) { $audiofile = "main.wav";

echo '<EMBED SRC="'.$audiofile.'" HIDDEN="TRUE" AUTOSTART="TRUE"></EMBED>'; } }?>

Last for the PHP we call the Function!

Soundm();

<?php function soundm(){ if (isset($_GET['wav'])) { $audiofile = "main.wav";

echo '<EMBED SRC="'.$audiofile.'" HIDDEN="TRUE" AUTOSTART="TRUE"></EMBED>'; } Soundm(); }?>

Finnaly the HTML for the Hyperlink, actual HTML that the web browser compiles:

<a href='index.php?wav=true'>Say It!</a>

That's all! Hope you all enjoy.

Next:

Linux BASH and PHP | Arduino and PHP | PHP Cronjobs | PHP Sercurity | PHP MySql | PHP API Call XML/ CSV

All code tested on a WAMP and LAMP stack, WAMP being XAMPP and the LAMP being a Service Provider.

@Crabb

CNC

wavTue, 12 Dec 2017 13:35:20 -0600 54.147.40.153 wav