PHP MPD Class

Most mpd.class.php's are old and produce a lot of errors which caused me much frustration in this thread.
I was wrapping my head around why phpmpreloaded worked and the others never and it's because it uses an updated mpd.class.php. To save others the frustration and hassle I figured I'd post the new class here.
Enjoy.
<?php
* Sven Ginka 03/2010
* Version mpd.class.php-1.3
* - take over from Hendrik Stoetter
* - removed "split()" as this function is marked depracted
* - added property "xfade" (used by IPodMp, phpMp+)
* - added property "bitrate" (used by phpMp+)
* - added define "MPD_SEARCH_FILENAME"
* - included sorting algorithm "msort"
* - added function validateFile() for guessing a title if no ID3 data is given
* Hendrik Stoetter 03/2008
* - this a lightly modified version of mod.class Version 1.2.
* - fixed some bugs and added some new functions
* - Changes:
* GetDir($url) -> GetDir(url,$sort)
* var $stats
* Benjamin Carlisle 05/05/2004
* mpd.class.php - PHP Object Interface to the MPD Music Player Daemon
* Version 1.2, Released 05/05/2004
* Copyright (C) 2003-2004 Benjamin Carlisle ([email protected])
* http://mpd.24oz.com/ | http://www.musicpd.org/
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// Create common command definitions for MPD to use
define("MPD_CMD_STATUS", "status");
define("MPD_CMD_STATISTICS", "stats");
define("MPD_CMD_VOLUME", "volume");
define("MPD_CMD_SETVOL", "setvol");
define("MPD_CMD_PLAY", "play");
define("MPD_CMD_STOP", "stop");
define("MPD_CMD_PAUSE", "pause");
define("MPD_CMD_NEXT", "next");
define("MPD_CMD_PREV", "previous");
define("MPD_CMD_PLLIST", "playlistinfo");
define("MPD_CMD_PLADD", "add");
define("MPD_CMD_PLREMOVE", "delete");
define("MPD_CMD_PLCLEAR", "clear");
define("MPD_CMD_PLSHUFFLE", "shuffle");
define("MPD_CMD_PLLOAD", "load");
define("MPD_CMD_PLSAVE", "save");
define("MPD_CMD_KILL", "kill");
define("MPD_CMD_REFRESH", "update");
define("MPD_CMD_REPEAT", "repeat");
define("MPD_CMD_LSDIR", "lsinfo");
define("MPD_CMD_SEARCH", "search");
define("MPD_CMD_START_BULK", "command_list_begin");
define("MPD_CMD_END_BULK", "command_list_end");
define("MPD_CMD_FIND", "find");
define("MPD_CMD_RANDOM", "random");
define("MPD_CMD_SEEK", "seek");
define("MPD_CMD_PLSWAPTRACK", "swap");
define("MPD_CMD_PLMOVETRACK", "move");
define("MPD_CMD_PASSWORD", "password");
define("MPD_CMD_TABLE", "list");
define("MPD_CMD_PLMOVE", "move" );
// Predefined MPD Response messages
define("MPD_RESPONSE_ERR", "ACK");
define("MPD_RESPONSE_OK", "OK");
// MPD State Constants
define("MPD_STATE_PLAYING", "play");
define("MPD_STATE_STOPPED", "stop");
define("MPD_STATE_PAUSED", "pause");
// MPD Searching Constants
define("MPD_SEARCH_ARTIST", "artist");
define("MPD_SEARCH_TITLE", "title");
define("MPD_SEARCH_ALBUM", "album");
define("MPD_SEARCH_ANY", "any");
define("MPD_SEARCH_FILENAME","filename");
// MPD Cache Tables
define("MPD_TBL_ARTIST","artist");
define("MPD_TBL_ALBUM","album");
$mpd_debug = 0;
function addLog($text){
global $mpd_debug;
$style="background-color:lightgrey;border:thin solid grey;margin:5px;padding:5px";
if ($mpd_debug) echo '<div style="'.$style.'">log:>'.$text.'</div>';
function addErr($err){
global $mpd_debug;
if ($mpd_debug) echo 'error:>'.$err.'<br>';
class mpd {
// TCP/Connection variables
var $host;
var $port;
var $password;
var $mpd_sock = NULL;
var $connected = FALSE;
// MPD Status variables
var $mpd_version = "(unknown)";
var $state;
var $current_track_position;
var $current_track_length;
var $current_track_id;
var $volume;
var $repeat;
var $random;
var $uptime;
var $playtime;
var $db_last_refreshed;
var $num_songs_played;
var $playlist_count;
var $xfade;
var $bitrate;
var $num_artists;
var $num_albums;
var $num_songs;
var $playlist = array();
var $stats;
// Misc Other Vars
var $mpd_class_version = "1.2";
var $debugging = FALSE; // Set to TRUE to turn extended debugging on.
var $errStr = ""; // Used for maintaining information about the last error message
var $command_queue; // The list of commands for bulk command sending
// =================== BEGIN OBJECT METHODS ================
/* mpd() : Constructor
* Builds the MPD object, connects to the server, and refreshes all local object properties.
function mpd($srv,$port,$pwd = NULL, $debug= FALSE ) {
$this->host = $srv;
$this->port = $port;
$this->password = $pwd;
$this->debugging = $debug;
global $mpd_debug;
$mpd_debug = $debug;
$resp = $this->Connect();
if ( is_null($resp) ) {
addErr( "Could not connect" );
return;
} else {
addLog( "connected");
list ( $this->mpd_version ) = sscanf($resp, MPD_RESPONSE_OK . " MPD %s\n");
if ( ! is_null($pwd) ) {
if ( is_null($this->SendCommand(MPD_CMD_PASSWORD,$pwd)) ) {
$this->connected = FALSE;
addErr("bad password");
return; // bad password or command
if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected!
$this->connected = FALSE;
addErr("Password supplied does not have read access");
return;
} else {
if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected!
$this->connected = FALSE;
addErr("Password required to access server");
return;
/* Connect()
* Connects to the MPD server.
* NOTE: This is called automatically upon object instantiation; you should not need to call this directly.
function Connect() {
addLog( "mpd->Connect() / host: ".$this->host.", port: ".$this->port."\n" );
$this->mpd_sock = fsockopen($this->host,$this->port,$errNo,$errStr,10);
if (!$this->mpd_sock) {
addErr("Socket Error: $errStr ($errNo)");
return NULL;
} else {
$counter=0;
while(!feof($this->mpd_sock)) {
$counter++;
if ($counter > 10){
addErr("no file end");
return NULL;
$response = fgets($this->mpd_sock,1024);
addLog( $response );
if (strncmp(MPD_RESPONSE_OK,$response,strlen(MPD_RESPONSE_OK)) == 0) {
$this->connected = TRUE;
return $response;
if (strncmp(MPD_RESPONSE_ERR,$response,strlen(MPD_RESPONSE_ERR)) == 0) {
// close socket
fclose($this->mpd_sock);
addErr("Server responded with: $response");
return NULL;
// close socket
fclose($this->mpd_sock);
// Generic response
addErr("Connection not available");
return NULL;
/* SendCommand()
* Sends a generic command to the MPD server. Several command constants are pre-defined for
* use (see MPD_CMD_* constant definitions above).
function SendCommand($cmdStr,$arg1 = "",$arg2 = "") {
addLog("mpd->SendCommand() / cmd: ".$cmdStr.", args: ".$arg1." ".$arg2 );
// Clear out the error String
$this->errStr = NULL;
$respStr = "";
if ( ! $this->connected ) {
addErr( "mpd->SendCommand() / Error: Not connected");
} else {
// Check the command compatibility:
if ( ! $this->_checkCompatibility($cmdStr) ) {
return NULL;
if (strlen($arg1) > 0) $cmdStr .= " \"$arg1\"";
if (strlen($arg2) > 0) $cmdStr .= " \"$arg2\"";
fputs($this->mpd_sock,"$cmdStr\n");
while(!feof($this->mpd_sock)) {
$response = fgets($this->mpd_sock,1024);
//addLog($response);
// An OK signals the end of transmission -- we'll ignore it
if (strncmp(MPD_RESPONSE_OK,$response,strlen(MPD_RESPONSE_OK)) == 0) {
break;
// An ERR signals the end of transmission with an error! Let's grab the single-line message.
if (strncmp(MPD_RESPONSE_ERR,$response,strlen(MPD_RESPONSE_ERR)) == 0) {
list ( $junk, $errTmp ) = strtok(MPD_RESPONSE_ERR . " ",$response );
addErr( strtok($errTmp,"\n") );
return NULL;
// Build the response string
$respStr .= $response;
addLog("mpd->SendCommand() / response: '".$respStr."'\n");
return $respStr;
/* QueueCommand()
* Queues a generic command for later sending to the MPD server. The CommandQueue can hold
* as many commands as needed, and are sent all at once, in the order they are queued, using
* the SendCommandQueue() method. The syntax for queueing commands is identical to SendCommand().
function QueueCommand($cmdStr,$arg1 = "",$arg2 = "") {
if ( $this->debugging ) echo "mpd->QueueCommand() / cmd: ".$cmdStr.", args: ".$arg1." ".$arg2."\n";
if ( ! $this->connected ) {
echo "mpd->QueueCommand() / Error: Not connected\n";
return NULL;
} else {
if ( strlen($this->command_queue) == 0 ) {
$this->command_queue = MPD_CMD_START_BULK . "\n";
if (strlen($arg1) > 0) $cmdStr .= " \"$arg1\"";
if (strlen($arg2) > 0) $cmdStr .= " \"$arg2\"";
$this->command_queue .= $cmdStr ."\n";
if ( $this->debugging ) echo "mpd->QueueCommand() / return\n";
return TRUE;
/* SendCommandQueue()
* Sends all commands in the Command Queue to the MPD server. See also QueueCommand().
function SendCommandQueue() {
if ( $this->debugging ) echo "mpd->SendCommandQueue()\n";
if ( ! $this->connected ) {
echo "mpd->SendCommandQueue() / Error: Not connected\n";
return NULL;
} else {
$this->command_queue .= MPD_CMD_END_BULK . "\n";
if ( is_null($respStr = $this->SendCommand($this->command_queue)) ) {
return NULL;
} else {
$this->command_queue = NULL;
if ( $this->debugging ) echo "mpd->SendCommandQueue() / response: '".$respStr."'\n";
return $respStr;
/* AdjustVolume()
* Adjusts the mixer volume on the MPD by <modifier>, which can be a positive (volume increase),
* or negative (volume decrease) value.
function AdjustVolume($modifier) {
if ( $this->debugging ) echo "mpd->AdjustVolume()\n";
if ( ! is_numeric($modifier) ) {
$this->errStr = "AdjustVolume() : argument 1 must be a numeric value";
return NULL;
$this->RefreshInfo();
$newVol = $this->volume + $modifier;
$ret = $this->SetVolume($newVol);
if ( $this->debugging ) echo "mpd->AdjustVolume() / return\n";
return $ret;
/* SetVolume()
* Sets the mixer volume to <newVol>, which should be between 1 - 100.
function SetVolume($newVol) {
if ( $this->debugging ) echo "mpd->SetVolume()\n";
if ( ! is_numeric($newVol) ) {
$this->errStr = "SetVolume() : argument 1 must be a numeric value";
return NULL;
// Forcibly prevent out of range errors
if ( $newVol < 0 ) $newVol = 0;
if ( $newVol > 100 ) $newVol = 100;
// If we're not compatible with SETVOL, we'll try adjusting using VOLUME
if ( $this->_checkCompatibility(MPD_CMD_SETVOL) ) {
if ( ! is_null($ret = $this->SendCommand(MPD_CMD_SETVOL,$newVol))) $this->volume = $newVol;
} else {
$this->RefreshInfo(); // Get the latest volume
if ( is_null($this->volume) ) {
return NULL;
} else {
$modifier = ( $newVol - $this->volume );
if ( ! is_null($ret = $this->SendCommand(MPD_CMD_VOLUME,$modifier))) $this->volume = $newVol;
if ( $this->debugging ) echo "mpd->SetVolume() / return\n";
return $ret;
/* GetDir()
* Retrieves a database directory listing of the <dir> directory and places the results into
* a multidimensional array. If no directory is specified, the directory listing is at the
* base of the MPD music path.
function GetDir($dir = "",$sort = "") {
addLog( "mpd->GetDir()" );
$resp = $this->SendCommand(MPD_CMD_LSDIR,$dir);
$listArray = $this->_parseFileListResponse($resp);
if ($listArray==null){
return null;
// we have 3 differnt items: directory, playlist and file
// we have to sort them individually and separate
// playlist and directory by name
// file by $sort
// 1st: subarrays
$array_directory = $listArray['directories'];
$array_playlist = $listArray['playlists'];
$array_file = $listArray['files'];
// 2nd: sort them
natcasesort($array_directory);
natcasesort($array_playlist);
usort($array_file,"msort");
// 3rd: rebuild
$array_return= array(
"directories"=> $array_directory,
"playlists"=> $array_playlist,
"files"=> $array_file
foreach ($array_directory as $value) {
$array_return[]["directory"] = $value;
foreach ($array_playlist as $value) {
$array_return[]["playlist"] = $value;
$array_return = array_merge($array_return,$array_file);
addLog( "mpd->GetDir() / return ".print_r($array_return,true));
return $array_return;
/* GetDirTest() (Unoffical add) -- Returns readable dir contents
* Retrieves a database directory listing of the <dir> directory and places the results into
* a multidimensional array. If no directory is specified, the directory listing is at the
* base of the MPD music path.
function GetDirTest($dir = "") {
if ( $this->debugging ) echo "mpd->GetDir()\n";
$resp = $this->SendCommand(MPD_CMD_LSDIR,$dir);
#$dirlist = $this->_parseFileListResponse($resp);
$dirlist = $this->_parseFileListResponseHumanReadable($resp);
if ( $this->debugging ) echo "mpd->GetDir() / return ".print_r($dirlist)."\n";
return $dirlist;
/* PLAdd()
* Adds each track listed in a single-dimensional <trackArray>, which contains filenames
* of tracks to add, to the end of the playlist. This is used to add many, many tracks to
* the playlist in one swoop.
function PLAddBulk($trackArray) {
if ( $this->debugging ) echo "mpd->PLAddBulk()\n";
$num_files = count($trackArray);
for ( $i = 0; $i < $num_files; $i++ ) {
$this->QueueCommand(MPD_CMD_PLADD,$trackArray[$i]);
$resp = $this->SendCommandQueue();
$this->RefreshInfo();
if ( $this->debugging ) echo "mpd->PLAddBulk() / return\n";
return $resp;
/* PLAdd()
* Adds the file <file> to the end of the playlist. <file> must be a track in the MPD database.
function PLAdd($fileName) {
if ( $this->debugging ) echo "mpd->PLAdd()\n";
if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLADD,$fileName))) $this->RefreshInfo();
if ( $this->debugging ) echo "mpd->PLAdd() / return\n";
return $resp;
/* PLMoveTrack()
* Moves track number <origPos> to position <newPos> in the playlist. This is used to reorder
* the songs in the playlist.
function PLMoveTrack($origPos, $newPos) {
if ( $this->debugging ) echo "mpd->PLMoveTrack()\n";
if ( ! is_numeric($origPos) ) {
$this->errStr = "PLMoveTrack(): argument 1 must be numeric";
return NULL;
if ( $origPos < 0 or $origPos > $this->playlist_count ) {
$this->errStr = "PLMoveTrack(): argument 1 out of range";
return NULL;
if ( $newPos < 0 ) $newPos = 0;
if ( $newPos > $this->playlist_count ) $newPos = $this->playlist_count;
if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLMOVETRACK,$origPos,$newPos))) $this->RefreshInfo();
if ( $this->debugging ) echo "mpd->PLMoveTrack() / return\n";
return $resp;
/* PLShuffle()
* Randomly reorders the songs in the playlist.
function PLShuffle() {
if ( $this->debugging ) echo "mpd->PLShuffle()\n";
if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLSHUFFLE))) $this->RefreshInfo();
if ( $this->debugging ) echo "mpd->PLShuffle() / return\n";
return $resp;
/* PLLoad()
* Retrieves the playlist from <file>.m3u and loads it into the current playlist.
function PLLoad($file) {
if ( $this->debugging ) echo "mpd->PLLoad()\n";
if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLLOAD,$file))) $this->RefreshInfo();
if ( $this->debugging ) echo "mpd->PLLoad() / return\n";
return $resp;
/* PLSave()
* Saves the playlist to <file>.m3u for later retrieval. The file is saved in the MPD playlist
* directory.
function PLSave($file) {
if ( $this->debugging ) echo "mpd->PLSave()\n";
$resp = $this->SendCommand(MPD_CMD_PLSAVE,$file);
if ( $this->debugging ) echo "mpd->PLSave() / return\n";
return $resp;
/* PLClear()
* Empties the playlist.
function PLClear() {
if ( $this->debugging ) echo "mpd->PLClear()\n";
if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLCLEAR))) $this->RefreshInfo();
if ( $this->debugging ) echo "mpd->PLClear() / return\n";
return $resp;
/* PLRemove()
* Removes track <id> from the playlist.
function PLRemove($id) {
if ( $this->debugging ) echo "mpd->PLRemove()\n";
if ( ! is_numeric($id) ) {
$this->errStr = "PLRemove() : argument 1 must be a numeric value";
return NULL;
if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLREMOVE,$id))) $this->RefreshInfo();
if ( $this->debugging ) echo "mpd->PLRemove() / return\n";
return $resp;
/* SetRepeat()
* Enables 'loop' mode -- tells MPD continually loop the playlist. The <repVal> parameter
* is either 1 (on) or 0 (off).
function SetRepeat($repVal) {
if ( $this->debugging ) echo "mpd->SetRepeat()\n";
$rpt = $this->SendCommand(MPD_CMD_REPEAT,$repVal);
$this->repeat = $repVal;
if ( $this->debugging ) echo "mpd->SetRepeat() / return\n";
return $rpt;
/* SetRandom()
* Enables 'randomize' mode -- tells MPD to play songs in the playlist in random order. The
* <rndVal> parameter is either 1 (on) or 0 (off).
function SetRandom($rndVal) {
if ( $this->debugging ) echo "mpd->SetRandom()\n";
$resp = $this->SendCommand(MPD_CMD_RANDOM,$rndVal);
$this->random = $rndVal;
if ( $this->debugging ) echo "mpd->SetRandom() / return\n";
return $resp;
/* Shutdown()
* Shuts down the MPD server (aka sends the KILL command). This closes the current connection,
* and prevents future communication with the server.
function Shutdown() {
if ( $this->debugging ) echo "mpd->Shutdown()\n";
$resp = $this->SendCommand(MPD_CMD_SHUTDOWN);
$this->connected = FALSE;
unset($this->mpd_version);
unset($this->errStr);
unset($this->mpd_sock);
if ( $this->debugging ) echo "mpd->Shutdown() / return\n";
return $resp;
/* DBRefresh()
* Tells MPD to rescan the music directory for new tracks, and to refresh the Database. Tracks
* cannot be played unless they are in the MPD database.
function DBRefresh() {
if ( $this->debugging ) echo "mpd->DBRefresh()\n";
$resp = $this->SendCommand(MPD_CMD_REFRESH);
// Update local variables
$this->RefreshInfo();
if ( $this->debugging ) echo "mpd->DBRefresh() / return\n";
return $resp;
/* Play()
* Begins playing the songs in the MPD playlist.
function Play() {
if ( $this->debugging ) echo "mpd->Play()\n";
if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PLAY) )) $this->RefreshInfo();
if ( $this->debugging ) echo "mpd->Play() / return\n";
return $rpt;
/* Stop()
* Stops playing the MPD.
function Stop() {
if ( $this->debugging ) echo "mpd->Stop()\n";
if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_STOP) )) $this->RefreshInfo();
if ( $this->debugging ) echo "mpd->Stop() / return\n";
return $rpt;
/* Pause()
* Toggles pausing on the MPD. Calling it once will pause the player, calling it again
* will unpause.
function Pause() {
if ( $this->debugging ) echo "mpd->Pause()\n";
if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PAUSE) )) $this->RefreshInfo();
if ( $this->debugging ) echo "mpd->Pause() / return\n";
return $rpt;
/* SeekTo()
* Skips directly to the <idx> song in the MPD playlist.
function SkipTo($idx) {
if ( $this->debugging ) echo "mpd->SkipTo()\n";
if ( ! is_numeric($idx) ) {
$this->errStr = "SkipTo() : argument 1 must be a numeric value";
return NULL;
if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PLAY,$idx))) $this->RefreshInfo();
if ( $this->debugging ) echo "mpd->SkipTo() / return\n";
return $idx;
/* SeekTo()
* Skips directly to a given position within a track in the MPD playlist. The <pos> argument,
* given in seconds, is the track position to locate. The <track> argument, if supplied is
* the track number in the playlist. If <track> is not specified, the current track is assumed.
function SeekTo($pos, $track = -1) {
if ( $this->debugging ) echo "mpd->SeekTo()\n";
if ( ! is_numeric($pos) ) {
$this->errStr = "SeekTo() : argument 1 must be a numeric value";
return NULL;
if ( ! is_numeric($track) ) {
$this->errStr = "SeekTo() : argument 2 must be a numeric value";
return NULL;
if ( $track == -1 ) {
$track = $this->current_track_id;
if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_SEEK,$track,$pos))) $this->RefreshInfo();
if ( $this->debugging ) echo "mpd->SeekTo() / return\n";
return $pos;
/* Next()
* Skips to the next song in the MPD playlist. If not playing, returns an error.
function Next() {
if ( $this->debugging ) echo "mpd->Next()\n";
if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_NEXT))) $this->RefreshInfo();
if ( $this->debugging ) echo "mpd->Next() / return\n";
return $rpt;
/* Previous()
* Skips to the previous song in the MPD playlist. If not playing, returns an error.
function Previous() {
if ( $this->debugging ) echo "mpd->Previous()\n";
if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PREV))) $this->RefreshInfo();
if ( $this->debugging ) echo "mpd->Previous() / return\n";
return $rpt;
/* Search()
* Searches the MPD database. The search <type> should be one of the following:
* MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM
* The search <string> is a case-insensitive locator string. Anything that contains
* <string> will be returned in the results.
function Search($type,$string) {
addLog("mpd->Search()");
if ( $type != MPD_SEARCH_ARTIST and
$type != MPD_SEARCH_ALBUM and
$type != MPD_SEARCH_ANY and
$type != MPD_SEARCH_TITLE ) {
addErr( "mpd->Search(): invalid search type" );
return NULL;
} else {
if ( is_null($resp = $this->SendCommand(MPD_CMD_SEARCH,$type,$string))) return NULL;
$searchlist = $this->_parseFileListResponse($resp);
addLog( "mpd->Search() / return ".print_r($searchlist,true) );
return $searchlist;
/* Find()
* Find() looks for exact matches in the MPD database. The find <type> should be one of
* the following:
* MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM
* The find <string> is a case-insensitive locator string. Anything that exactly matches
* <string> will be returned in the results.
function Find($type,$string) {
if ( $this->debugging ) echo "mpd->Find()\n";
if ( $type != MPD_SEARCH_ARTIST and
$type != MPD_SEARCH_ALBUM and
$type != MPD_SEARCH_TITLE ) {
$this->errStr = "mpd->Find(): invalid find type";
return NULL;
} else {
if ( is_null($resp = $this->SendCommand(MPD_CMD_FIND,$type,$string))) return NULL;
$searchlist = $this->_parseFileListResponse($resp);
if ( $this->debugging ) echo "mpd->Find() / return ".print_r($searchlist)."\n";
return $searchlist;
/* Disconnect()
* Closes the connection to the MPD server.
function Disconnect() {
if ( $this->debugging ) echo "mpd->Disconnect()\n";
fclose($this->mpd_sock);
$this->connected = FALSE;
unset($this->mpd_version);
unset($this->errStr);
unset($this->mpd_sock);
/* GetArtists()
* Returns the list of artists in the database in an associative array.
function GetArtists() {
if ( $this->debugging ) echo "mpd->GetArtists()\n";
if ( is_null($resp = $this->SendCommand(MPD_CMD_TABLE, MPD_TBL_ARTIST))) return NULL;
$arArray = array();
$arLine = strtok($resp,"\n");
$arName = "";
$arCounter = -1;
while ( $arLine ) {
list ( $element, $value ) = explode(": ",$arLine);
if ( $element == "Artist" ) {
$arCounter++;
$arName = $value;
$arArray[$arCounter] = $arName;
$arLine = strtok("\n");
if ( $this->debugging ) echo "mpd->GetArtists()\n";
return $arArray;
/* GetAlbums()
* Returns the list of albums in the database in an associative array. Optional parameter
* is an artist Name which will list all albums by a particular artist.
function GetAlbums( $ar = NULL) {
if ( $this->debugging ) echo "mpd->GetAlbums()\n";
if ( is_null($resp = $this->SendCommand(MPD_CMD_TABLE, MPD_TBL_ALBUM, $ar ))) return NULL;
$alArray = array();
$alLine = strtok($resp,"\n");
$alName = "";
$alCounter = -1;
while ( $alLine ) {
list ( $element, $value ) = explode(": ",$alLine);
if ( $element == "Album" ) {
$alCounter++;
$alName = $value;
$alArray[$alCounter] = $alName;
$alLine = strtok("\n");
if ( $this->debugging ) echo "mpd->GetAlbums()\n";
return $alArray;
//***************************** INTERNAL FUNCTIONS ******************************//
/* _computeVersionValue()
* Computes a compatibility value from a version string
private function _computeVersionValue($verStr) {
list ($ver_maj, $ver_min, $ver_rel ) = explode(".",$verStr);
return ( 100 * $ver_maj ) + ( 10 * $ver_min ) + ( $ver_rel );
/* _checkCompatibility()
* Check MPD command compatibility against our internal table. If there is no version
* listed in the table, allow it by default.
private function _checkCompatibility($cmd) {
// Check minimum compatibility
if (isset($this->COMPATIBILITY_MIN_TBL[$cmd])){
$req_ver_low = $this->COMPATIBILITY_MIN_TBL[$cmd];
} else {
$req_ver_low = "0.9.1";
// check max compatibility
if (isset($this->COMPATIBILITY_MAX_TBL[$cmd])){
$req_ver_hi = $this->COMPATIBILITY_MAX_TBL[$cmd];
} else {
$req_ver_hi = "0.20.0";
$mpd_ver = $this->_computeVersionValue($this->mpd_version);
if ( $req_ver_low ) {
$req_ver = $this->_computeVersionValue($req_ver_low);
if ( $mpd_ver < $req_ver ) {
addErr("Command '$cmd' is not compatible with this version of MPD, version ".$req_ver_low." required");
return FALSE;
// Check maximum compatibility -- this will check for deprecations
if ( $req_ver_hi ) {
$req_ver = $this->_computeVersionValue($req_ver_hi);
if ( $mpd_ver > $req_ver ) {
addErr("Command '$cmd' has been deprecated in this version of MPD.");
return FALSE;
return TRUE;
* checks the file entry and complete it if necesarry
* checked fields are 'Artist', 'Genre' and 'Title'
private function _validateFile( $fileItem ){
$filename = $fileItem['file'];
if (!isset($fileItem['Artist'])){ $fileItem['Artist']=null; }
if (!isset($fileItem['Genre'])){ $fileItem['Genre']=null; }
// special conversion for streams
if (stripos($filename, 'http' )!==false){
if (!isset($fileItem['Title'])) $title = ''; else $title=$fileItem['Title'];
if (!isset($fileItem['Name'])) $name = ''; else $name=$fileItem['Name'];
if (!isset($fileItem['Artist'])) $artist = ''; else $artist=$fileItem['Artist'];
if (strlen($title.$name.$artist)==0){
$fileItem['Title'] = $filename;
} else {
$fileItem['Title'] = 'stream://'.$title.' '.$name.' '.$artist;
if (!isset($fileItem['Title'])){
$file_parts = explode('/', $filename);
$fileItem['Title'] = $filename;
return $fileItem;
* take the response of mpd and split it up into
* items of types 'file', 'directory' and 'playlist'
private function _extractItems( $resp ){
if ( $resp == null ) {
addLog('empty file list');
return NULL;
// strip unwanted chars
$resp = trim($resp);
// split up into lines
$lineList = explode("\n", $resp );
$array = array();
$item=null;
foreach ($lineList as $line ){
list ( $element, $value ) = explode(": ",$line);
// if one of the key words come up, store the item
if (($element == "directory") or ($element=="playlist") or ($element=="file")){
if ($item){
$array[] = $item;
$item = array();
$item[$element] = $value;
// check if there is a last item to store
if (sizeof($item)>0){
$array[] = $item;
return $array;
/* _parseFileListResponse()
* Builds a multidimensional array with MPD response lists.
* NOTE: This function is used internally within the class. It should not be used.
private function _parseFileListResponse($resp) {
$valuesArray = $this->_extractItems( $resp );
if ($valuesArray == null ){
return null;
//1. create empty arrays
$directoriesArray = array();
$filesArray = array();
$playlistsArray = array();
//2. sort the items
foreach ( $valuesArray as $item ) {
if (isset($item['file'])){
$filesArray[] = $this->_validateFile($item);
} else if (isset($item['directory'])){
$directoriesArray[] = $item['directory'];
} else if (isset($item['playlist'])){
$playlistsArray[] = $item['playlist'];
} else {
addErr('should not enter this');
//3. create a combined list of items
$returnArray = array(
"directories"=>$directoriesArray,
"playlists"=>$playlistsArray,
"files"=>$filesArray
addLog( print_r($valuesArray,true) );
return $returnArray;
/* RefreshInfo()
* Updates all class properties with the values from the MPD server.
* NOTE: This function is automatically called upon Connect() as of v1.1.
function RefreshInfo() {
// Get the Server Statistics
$statStr = $this->SendCommand(MPD_CMD_STATISTICS);
if ( !$statStr ) {
return NULL;
} else {
$stats = array();
$statStr=trim($statStr);
$statLine = explode( "\n", $statStr );
foreach ( $statLine as $line ) {
list ( $element, $value ) = explode(": ",$line);
$stats[$element] = $value;
// Get the Server Status
$statusStr = $this->SendCommand(MPD_CMD_STATUS);
if ( ! $statusStr ) {
return NULL;
} else {
$status = array();
$statusStr=trim($statusStr);
$statusLine = explode("\n", $statusStr );
foreach ( $statusLine as $line ) {
list ( $element, $value ) = explode(": ",$line);
$status[$element] = $value;
// Get the Playlist
$plStr = $this->SendCommand(MPD_CMD_PLLIST);
$array = $this->_parseFileListResponse($plStr);
$playlist = $array['files'];
$this->playlist_count = count($playlist);
$this->playlist = array();
if (sizeof($playlist)>0){
foreach ($playlist as $item ){
$this->playlist[$item['Pos']]=$item;
// Set Misc Other Variables
$this->state = $status['state'];
if ( ($this->state == MPD_STATE_PLAYING) || ($this->state == MPD_STATE_PAUSED) ) {
$this->current_track_id = $status['song'];
list ($this->current_track_position, $this->current_track_length ) = explode(":",$status['time']);
} else {
$this->current_track_id = -1;
$this->current_track_position = -1;
$this->current_track_length = -1;
$this->repeat = $status['repeat'];
$this->random = $status['random'];
$this->db_last_refreshed = $stats['db_update'];
$this->volume = $status['volume'];
$this->uptime = $stats['uptime'];
$this->playtime = $stats['playtime'];
$this->num_songs_played = $stats['songs'];
$this->num_artists = $stats['artists'];
$this->num_songs = $stats['songs'];
$this->num_albums = $stats['albums'];
$this->xfade = $status['xfade'];
if(isset($status['bitrate'])) $this->bitrate = $status['bitrate'];
else $this->bitrate = FALSE;
return TRUE;
/* ------------------ DEPRECATED METHODS -------------------*/
/* GetStatistics()
* Retrieves the 'statistics' variables from the server and tosses them into an array.
* NOTE: This function really should not be used. Instead, use $this->[variable]. The function
* will most likely be deprecated in future releases.
function GetStatistics() {
if ( $this->debugging ) echo "mpd->GetStatistics()\n";
$stats = $this->SendCommand(MPD_CMD_STATISTICS);
if ( !$stats ) {
return NULL;
} else {
$statsArray = array();
$statsLine = strtok($stats,"\n");
while ( $statsLine ) {
list ( $element, $value ) = explode(": ",$statsLine);
$statsArray[$element] = $value;
$statsLine = strtok("\n");
if ( $this->debugging ) echo "mpd->GetStatistics() / return: " . print_r($statsArray) ."\n";
return $statsArray;
/* GetStatus()
* Retrieves the 'status' variables from the server and tosses them into an array.
* NOTE: This function really should not be used. Instead, use $this->[variable]. The function
* will most likely be deprecated in future releases.
function GetStatus() {
if ( $this->debugging ) echo "mpd->GetStatus()\n";
$status = $this->SendCommand(MPD_CMD_STATUS);
if ( ! $status ) {
return NULL;
} else {
$statusArray = array();
$statusLine = strtok($status,"\n");
while ( $statusLine ) {
list ( $element, $value ) = explode(": ",$statusLine);
$statusArray[$element] = $value;
$statusLine = strtok("\n");
if ( $this->debugging ) echo "mpd->GetStatus() / return: " . print_r($statusArray) ."\n";
return $statusArray;
/* GetVolume()
* Retrieves the mixer volume from the server.
* NOTE: This function really should not be used. Instead, use $this->volume. The function
* will most likely be deprecated in future releases.
function GetVolume() {
if ( $this->debugging ) echo "mpd->GetVolume()\n";
$volLine = $this->SendCommand(MPD_CMD_STATUS);
if ( ! $volLine ) {
return NULL;
} else {
list ($vol) = sscanf($volLine,"volume: %d");
if ( $this->debugging ) echo "mpd->GetVolume() / return: $vol\n";
return $vol;
/* GetPlaylist()
* Retrieves the playlist from the server and tosses it into a multidimensional array.
* NOTE: This function really should not be used. Instead, use $this->playlist. The function
* will most likely be deprecated in future releases.
function GetPlaylist() {
if ( $this->debugging ) echo "mpd->GetPlaylist()\n";
$resp = $this->SendCommand(MPD_CMD_PLLIST);
$playlist = $this->_parseFileListResponse($resp);
if ( $this->debugging ) echo "mpd->GetPlaylist() / return ".print_r($playlist)."\n";
return $playlist;
/* ----------------- Command compatibility tables --------------------- */
var $COMPATIBILITY_MIN_TBL = array(
MPD_CMD_SEEK => "0.9.1" ,
MPD_CMD_PLMOVE => "0.9.1" ,
MPD_CMD_RANDOM => "0.9.1" ,
MPD_CMD_PLSWAPTRACK => "0.9.1" ,
MPD_CMD_PLMOVETRACK => "0.9.1" ,
MPD_CMD_PASSWORD => "0.10.0" ,
MPD_CMD_SETVOL => "0.10.0"
var $COMPATIBILITY_MAX_TBL = array(
MPD_CMD_VOLUME => "0.10.0"
} // ---------------------------- end of class ------------------------------
function msort($a,$b) {
global $sort_array,$filenames_only;
$i=0;
$ret = 0;
while($filenames_only!="yes" && $i<4 && $ret==0) {
if(!isset($a[$sort_array[$i]])) {
if(isset($b[$sort_array[$i]])) {
$ret = -1;
else if(!isset($b[$sort_array[$i]])) {
$ret = 1;
else if(strcmp($sort_array[$i],"Track")==0) {
$ret = strnatcmp($a[$sort_array[$i]],$b[$sort_array[$i]]);
else {
$ret = strcasecmp($a[$sort_array[$i]],$b[$sort_array[$i]]);
$i++;
if($ret==0)
$ret = strcasecmp($a["file"],$b["file"]);
return $ret;
function picksort($pick) {
global $sort_array;
if(0==strcmp($pick,$sort_array[0])) {
return "$sort_array[0],$sort_array[1],$sort_array[2],$sort_array[3]";
else if(0==strcmp($pick,$sort_array[1])) {
return "$pick,$sort_array[0],$sort_array[2],$sort_array[3]";
else if(0==strcmp($pick,$sort_array[2])) {
return "$pick,$sort_array[0],$sort_array[1],$sort_array[3]";
else if(0==strcmp($pick,$sort_array[3])) {
return "$pick,$sort_array[0],$sort_array[1],$sort_array[2]";
?>

BaconPie wrote:I used it to make a web based remote control for my phone. Glad it was of some help.
regarding the phone client, ... there is one in the phpMpReloaded project called IPodMp :-)
http://phpmpreloaded.sourceforge.net/sc … IPodMp.png
cheers
-tswaehn

Similar Messages

  • Omit the XML declaration when using the PHP MM_XSLTransform class

    Hi
    Is there any way to omit the XML declaration when using the
    PHP MM_XSLTransform class?
    When using the PHP MM_XSLTransform to transform some XML into
    HTML, the XML declaration is faithfully delivered, which is
    expected. In my case though this ends up in the body of the
    document and is not desired. I wish to choose that the XML
    declaration is not shown.
    I have tried to use the <xsl:output method="xml"
    encoding="utf-8" omit-xml-declaration="yes"/> in the XSL
    stylesheet but the declaration still appears.
    Any help?
    all the best
    Dave

    Jim20005 wrote:
    > I'm using XLS transfomation in DW for reading XML files.
    Now (I'm just back
    > form holiday), my webspace provider has updated to php
    5.1.5. I'm getting this
    > error:
    Comment out line 301 and add two new lines immediately after
    it like this:
    // $xml = DOMDocument::loadXML($content);
    $doc = new DOMDocument();
    $err = $doc->loadXML($content);
    This is part of a PHP 8.0.2 hotfix that can be obtained
    directly from
    Adobe support.
    David Powers
    Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    http://foundationphp.com/

  • PHP Authentication Class

    Hello,
    I just wanted to inform every that I have a php class 95% completed which basicilly mimics that of the perl script to authenticate. I'll be willing to share the script if anyone is interested.
    Aaron Axelsen
    UW-Whitewater

    The class was written for PHP5, and you must be running PHP4. Give this one a try: http://omega1.uww.edu/itunesu/itunes.php4.txt
    All the config file does is load in the global settings. You could make a config.php that holds the settings, or you can just modify the first function to actually have your information obtained from iTunes U instead of variables:
    $this->siteURL = "somesite";
    $this->debugSuffix = "/123456";
    $this->sharedSecret = "asdf";
    $this->administratorCredential = "Administrator@etc";

  • PHP arrow operator problem

    I'm half way through writing a web interface for mpd. I needed a way to interact with it so I searched around and found this. It's a php class that interfaces with mpd.
    I downloaded it and it comes with an example php file for using it. The only problem is that when I use the example page it just prints out anything after the arrow operator. As far as I'm aware the arrow operator is for accessing class methods and variables but I've never actually done any OOP with PHP.
    Anyway here is the example file:
    <?
    * mpd-class-example.php - Example interface using mpd.class.php
    * Version 1.2, released 05/05/2004
    * Copyright (C) 2003-2004 Benjamin Carlisle ([email protected])
    * http://mpd.24oz.com/ | http://www.musicpd.org/
    * This program illustrates the basic commands and usage of the MPD class.
    * *** PLEASE NOTE *** My intention in including this file is not to provide you with an
    * out-of-the-box MPD jukebox, but instead to provide a general understanding of how I saw
    * the class as being utilized. If you'd like to see more examples, please let me know. But
    * this should provide you with a good starting point for your own program development.
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation; either version 2 of the License, or
    * (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    ?>
    <HTML>
    <style type="text/css"><!-- .defaultText { font-family: Arial, Helvetica, sans-serif; font-size: 9pt; font-style: normal; font-weight: normal; color: #111111} .err { color: #DD3333 } --></style>
    <BODY class="defaultText">
    <?
    include('mpd.class.php');
    $myMpd = new mpd('localhost',2100);
    if ( $myMpd->connected == FALSE ) {
    echo "Error Connecting: " . $myMpd->errStr;
    } else {
    switch ($_REQUEST[m]) {
    case "add":
    if ( is_null($myMpd->PLAdd($_REQUEST[filename])) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
    break;
    case "rem":
    if ( is_null($myMpd->PLRemove($_REQUEST[id])) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
    break;
    case "setvol":
    if ( is_null($myMpd->SetVolume($_REQUEST[vol])) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
    break;
    case "play":
    if ( is_null($myMpd->Play()) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
    break;
    case "stop":
    if ( is_null($myMpd->Stop()) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
    break;
    case "pause":
    if ( is_null($myMpd->Pause()) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
    break;
    default:
    break;
    ?>
    <DIV ALIGN=CENTER>[ <A HREF="<? echo $_SERVER[PHP_SELF] ?>">Refresh Page</A> ]</DIV>
    <HR>
    <B>Connected to MPD Version <? echo $myMpd->mpd_version ?> at <? echo $myMpd->host ?>:<? echo $myMpd->port ?></B><BR>
    State:
    <?
    switch ($myMpd->state) {
    case MPD_STATE_PLAYING: echo "MPD is Playing [<A HREF='".$_SERVER[PHP_SELF]."?m=pause'>Pause</A>] [<A HREF='".$_SERVER[PHP_SELF]."?m=stop'>Stop</A>]"; break;
    case MPD_STATE_PAUSED: echo "MPD is Paused [<A HREF='".$_SERVER[PHP_SELF]."?m=pause'>Unpause</A>]"; break;
    case MPD_STATE_STOPPED: echo "MPD is Stopped [<A HREF='".$_SERVER[PHP_SELF]."?m=play'>Play</A>]"; break;
    default: echo "(Unknown State!)"; break;
    ?>
    <BR>
    Volume: <? echo $myMpd->volume ?> [ <A HREF='<? echo $_SERVER[PHP_SELF] ?>?m=setvol&vol=0'>0</A> | <A HREF='<? echo $_SERVER[PHP_SELF] ?>?m=setvol&vol=25'>25</A> | <A HREF='<? echo $_SERVER[PHP_SELF] ?>?m=setvol&vol=75'>75</A> | <A HREF='<? echo $_SERVER[PHP_SELF] ?>?m=setvol&vol=100'>100</A> ]<BR>
    Uptime: <? echo secToTimeStr($myMpd->uptime) ?><BR>
    Playtime: <? echo secToTimeStr($myMpd->playtime) ?><BR>
    <? if ( $myMpd->state == MPD_STATE_PLAYING or $myMpd->state == MPD_STATE_PAUSED ) { ?>
    Currently Playing: <? echo $myMpd->playlist[$myMpd->current_track_id]['Artist']." - ".$myMpd->playlist[$myMpd->current_track_id]['Title'] ?><BR>
    Track Position: <? echo $myMpd->current_track_position."/".$myMpd->current_track_length." (".(round(($myMpd->current_track_position/$myMpd->current_track_length),2)*100)."%)" ?><BR>
    Playlist Position: <? echo ($myMpd->current_track_id+1)."/".$myMpd->playlist_count." (".(round((($myMpd->current_track_id+1)/$myMpd->playlist_count),2)*100)."%)" ?><BR>
    <? } ?>
    <HR>
    <B>Playlist - Total: <? echo $myMpd->playlist_count ?> tracks (Click to Remove)</B><BR>
    <?
    if ( is_null($myMpd->playlist) ) echo "ERROR: " .$myMpd->errStr."\n";
    else {
    foreach ($myMpd->playlist as $id => $entry) {
    echo ( $id == $myMpd->current_track_id ? "<B>" : "" ) . ($id+1) . ". <A HREF='".$_SERVER[PHP_SELF]."?m=rem&id=".$id."'>".$entry['Artist']." - ".$entry['Title']."</A>".( $id == $myMpd->current_track_id ? "</B>" : "" )."<BR>\n";
    ?>
    <HR>
    <B>Sample Search for the String 'U2' (Click to Add to Playlist)</B><BR>
    <?
    $sl = $myMpd->Search(MPD_SEARCH_ARTIST,'U2');
    if ( is_null($sl) ) echo "ERROR: " .$myMpd->errStr."\n";
    else {
    foreach ($sl as $id => $entry) {
    echo ($id+1) . ": <A HREF='".$_SERVER[PHP_SELF]."?m=add&filename=".urlencode($entry['file'])."'>".$entry['Artist']." - ".$entry['Title']."</A><BR>\n";
    if ( count($sl) == 0 ) echo "<I>No results returned from search.</I>";
    // Example of how you would use Bulk Add features of MPD
    // $myarray = array();
    // $myarray[0] = "ACDC - Thunderstruck.mp3";
    // $myarray[1] = "ACDC - Back In Black.mp3";
    // $myarray[2] = "ACDC - Hells Bells.mp3";
    // if ( is_null($myMpd->PLAddBulk($myarray)) ) echo "ERROR: ".$myMpd->errStr."\n";
    ?>
    <HR>
    <B>Artist List</B><BR>
    <?
    if ( is_null($ar = $myMpd->GetArtists()) ) echo "ERROR: " .$myMpd->errStr."\n";
    else {
    while(list($key, $value) = each($ar) ) {
    echo ($key+1) . ". " . $value . "<BR>";
    $myMpd->Disconnect();
    // Used to make number of seconds perty.
    function secToTimeStr($secs) {
    $days = ($secs%604800)/86400;
    $hours = (($secs%604800)%86400)/3600;
    $minutes = ((($secs%604800)%86400)%3600)/60;
    $seconds = (((($secs%604800)%86400)%3600)%60);
    if (round($days)) $timestring .= round($days)."d ";
    if (round($hours)) $timestring .= round($hours)."h ";
    if (round($minutes)) $timestring .= round($minutes)."m";
    if (!round($minutes)&&!round($hours)&&!round($days)) $timestring.=" ".round($seconds)."s";
    return $timestring;
    ?>
    </BODY></HTML>
    The class file:
    <?php
    * mpd.class.php - PHP Object Interface to the MPD Music Player Daemon
    * Version 1.2, Released 05/05/2004
    * Copyright (C) 2003-2004 Benjamin Carlisle ([email protected])
    * http://mpd.24oz.com/ | http://www.musicpd.org/
    * This program is free software; you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation; either version 2 of the License, or
    * (at your option) any later version.
    * This program is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    * You should have received a copy of the GNU General Public License
    * along with this program; if not, write to the Free Software
    * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    // Create common command definitions for MPD to use
    define("MPD_CMD_STATUS", "status");
    define("MPD_CMD_STATISTICS", "stats");
    define("MPD_CMD_VOLUME", "volume");
    define("MPD_CMD_SETVOL", "setvol");
    define("MPD_CMD_PLAY", "play");
    define("MPD_CMD_STOP", "stop");
    define("MPD_CMD_PAUSE", "pause");
    define("MPD_CMD_NEXT", "next");
    define("MPD_CMD_PREV", "previous");
    define("MPD_CMD_PLLIST", "playlistinfo");
    define("MPD_CMD_PLADD", "add");
    define("MPD_CMD_PLREMOVE", "delete");
    define("MPD_CMD_PLCLEAR", "clear");
    define("MPD_CMD_PLSHUFFLE", "shuffle");
    define("MPD_CMD_PLLOAD", "load");
    define("MPD_CMD_PLSAVE", "save");
    define("MPD_CMD_KILL", "kill");
    define("MPD_CMD_REFRESH", "update");
    define("MPD_CMD_REPEAT", "repeat");
    define("MPD_CMD_LSDIR", "lsinfo");
    define("MPD_CMD_SEARCH", "search");
    define("MPD_CMD_START_BULK", "command_list_begin");
    define("MPD_CMD_END_BULK", "command_list_end");
    define("MPD_CMD_FIND", "find");
    define("MPD_CMD_RANDOM", "random");
    define("MPD_CMD_SEEK", "seek");
    define("MPD_CMD_PLSWAPTRACK", "swap");
    define("MPD_CMD_PLMOVETRACK", "move");
    define("MPD_CMD_PASSWORD", "password");
    define("MPD_CMD_TABLE", "list");
    // Predefined MPD Response messages
    define("MPD_RESPONSE_ERR", "ACK");
    define("MPD_RESPONSE_OK", "OK");
    // MPD State Constants
    define("MPD_STATE_PLAYING", "play");
    define("MPD_STATE_STOPPED", "stop");
    define("MPD_STATE_PAUSED", "pause");
    // MPD Searching Constants
    define("MPD_SEARCH_ARTIST", "artist");
    define("MPD_SEARCH_TITLE", "title");
    define("MPD_SEARCH_ALBUM", "album");
    // MPD Cache Tables
    define("MPD_TBL_ARTIST","artist");
    define("MPD_TBL_ALBUM","album");
    class mpd {
    // TCP/Connection variables
    var $host;
    var $port;
    var $password;
    var $mpd_sock = NULL;
    var $connected = FALSE;
    // MPD Status variables
    var $mpd_version = "(unknown)";
    var $state;
    var $current_track_position;
    var $current_track_length;
    var $current_track_id;
    var $volume;
    var $repeat;
    var $random;
    var $uptime;
    var $playtime;
    var $db_last_refreshed;
    var $num_songs_played;
    var $playlist_count;
    var $num_artists;
    var $num_albums;
    var $num_songs;
    var $playlist = array();
    // Misc Other Vars
    var $mpd_class_version = "1.2";
    var $debugging = FALSE; // Set to TRUE to turn extended debugging on.
    var $errStr = ""; // Used for maintaining information about the last error message
    var $command_queue; // The list of commands for bulk command sending
    // =================== BEGIN OBJECT METHODS ================
    /* mpd() : Constructor
    * Builds the MPD object, connects to the server, and refreshes all local object properties.
    function mpd($srv,$port,$pwd = NULL) {
    $this->host = $srv;
    $this->port = $port;
    $this->password = $pwd;
    $resp = $this->Connect();
    if ( is_null($resp) ) {
    $this->errStr = "Could not connect";
    return;
    } else {
    list ( $this->mpd_version ) = sscanf($resp, MPD_RESPONSE_OK . " MPD %s\n");
    if ( ! is_null($pwd) ) {
    if ( is_null($this->SendCommand(MPD_CMD_PASSWORD,$pwd)) ) {
    $this->connected = FALSE;
    return; // bad password or command
    if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected!
    $this->connected = FALSE;
    $this->errStr = "Password supplied does not have read access";
    return;
    } else {
    if ( is_null($this->RefreshInfo()) ) { // no read access -- might as well be disconnected!
    $this->connected = FALSE;
    $this->errStr = "Password required to access server";
    return;
    /* Connect()
    * Connects to the MPD server.
    * NOTE: This is called automatically upon object instantiation; you should not need to call this directly.
    function Connect() {
    if ( $this->debugging ) echo "mpd->Connect() / host: ".$this->host.", port: ".$this->port."\n";
    $this->mpd_sock = fsockopen($this->host,$this->port,$errNo,$errStr,10);
    if (!$this->mpd_sock) {
    $this->errStr = "Socket Error: $errStr ($errNo)";
    return NULL;
    } else {
    while(!feof($this->mpd_sock)) {
    $response = fgets($this->mpd_sock,1024);
    if (strncmp(MPD_RESPONSE_OK,$response,strlen(MPD_RESPONSE_OK)) == 0) {
    $this->connected = TRUE;
    return $response;
    break;
    if (strncmp(MPD_RESPONSE_ERR,$response,strlen(MPD_RESPONSE_ERR)) == 0) {
    $this->errStr = "Server responded with: $response";
    return NULL;
    // Generic response
    $this->errStr = "Connection not available";
    return NULL;
    /* SendCommand()
    * Sends a generic command to the MPD server. Several command constants are pre-defined for
    * use (see MPD_CMD_* constant definitions above).
    function SendCommand($cmdStr,$arg1 = "",$arg2 = "") {
    if ( $this->debugging ) echo "mpd->SendCommand() / cmd: ".$cmdStr.", args: ".$arg1." ".$arg2."\n";
    if ( ! $this->connected ) {
    echo "mpd->SendCommand() / Error: Not connected\n";
    } else {
    // Clear out the error String
    $this->errStr = "";
    $respStr = "";
    // Check the command compatibility:
    if ( ! $this->_checkCompatibility($cmdStr) ) {
    return NULL;
    if (strlen($arg1) > 0) $cmdStr .= " \"$arg1\"";
    if (strlen($arg2) > 0) $cmdStr .= " \"$arg2\"";
    fputs($this->mpd_sock,"$cmdStr\n");
    while(!feof($this->mpd_sock)) {
    $response = fgets($this->mpd_sock,1024);
    // An OK signals the end of transmission -- we'll ignore it
    if (strncmp(MPD_RESPONSE_OK,$response,strlen(MPD_RESPONSE_OK)) == 0) {
    break;
    // An ERR signals the end of transmission with an error! Let's grab the single-line message.
    if (strncmp(MPD_RESPONSE_ERR,$response,strlen(MPD_RESPONSE_ERR)) == 0) {
    list ( $junk, $errTmp ) = split(MPD_RESPONSE_ERR . " ",$response );
    $this->errStr = strtok($errTmp,"\n");
    if ( strlen($this->errStr) > 0 ) {
    return NULL;
    // Build the response string
    $respStr .= $response;
    if ( $this->debugging ) echo "mpd->SendCommand() / response: '".$respStr."'\n";
    return $respStr;
    /* QueueCommand()
    * Queues a generic command for later sending to the MPD server. The CommandQueue can hold
    * as many commands as needed, and are sent all at once, in the order they are queued, using
    * the SendCommandQueue() method. The syntax for queueing commands is identical to SendCommand().
    function QueueCommand($cmdStr,$arg1 = "",$arg2 = "") {
    if ( $this->debugging ) echo "mpd->QueueCommand() / cmd: ".$cmdStr.", args: ".$arg1." ".$arg2."\n";
    if ( ! $this->connected ) {
    echo "mpd->QueueCommand() / Error: Not connected\n";
    return NULL;
    } else {
    if ( strlen($this->command_queue) == 0 ) {
    $this->command_queue = MPD_CMD_START_BULK . "\n";
    if (strlen($arg1) > 0) $cmdStr .= " \"$arg1\"";
    if (strlen($arg2) > 0) $cmdStr .= " \"$arg2\"";
    $this->command_queue .= $cmdStr ."\n";
    if ( $this->debugging ) echo "mpd->QueueCommand() / return\n";
    return TRUE;
    /* SendCommandQueue()
    * Sends all commands in the Command Queue to the MPD server. See also QueueCommand().
    function SendCommandQueue() {
    if ( $this->debugging ) echo "mpd->SendCommandQueue()\n";
    if ( ! $this->connected ) {
    echo "mpd->SendCommandQueue() / Error: Not connected\n";
    return NULL;
    } else {
    $this->command_queue .= MPD_CMD_END_BULK . "\n";
    if ( is_null($respStr = $this->SendCommand($this->command_queue)) ) {
    return NULL;
    } else {
    $this->command_queue = NULL;
    if ( $this->debugging ) echo "mpd->SendCommandQueue() / response: '".$respStr."'\n";
    return $respStr;
    /* AdjustVolume()
    * Adjusts the mixer volume on the MPD by <modifier>, which can be a positive (volume increase),
    * or negative (volume decrease) value.
    function AdjustVolume($modifier) {
    if ( $this->debugging ) echo "mpd->AdjustVolume()\n";
    if ( ! is_numeric($modifier) ) {
    $this->errStr = "AdjustVolume() : argument 1 must be a numeric value";
    return NULL;
    $this->RefreshInfo();
    $newVol = $this->volume + $modifier;
    $ret = $this->SetVolume($newVol);
    if ( $this->debugging ) echo "mpd->AdjustVolume() / return\n";
    return $ret;
    /* SetVolume()
    * Sets the mixer volume to <newVol>, which should be between 1 - 100.
    function SetVolume($newVol) {
    if ( $this->debugging ) echo "mpd->SetVolume()\n";
    if ( ! is_numeric($newVol) ) {
    $this->errStr = "SetVolume() : argument 1 must be a numeric value";
    return NULL;
    // Forcibly prevent out of range errors
    if ( $newVol < 0 ) $newVol = 0;
    if ( $newVol > 100 ) $newVol = 100;
    // If we're not compatible with SETVOL, we'll try adjusting using VOLUME
    if ( $this->_checkCompatibility(MPD_CMD_SETVOL) ) {
    if ( ! is_null($ret = $this->SendCommand(MPD_CMD_SETVOL,$newVol))) $this->volume = $newVol;
    } else {
    $this->RefreshInfo(); // Get the latest volume
    if ( is_null($this->volume) ) {
    return NULL;
    } else {
    $modifier = ( $newVol - $this->volume );
    if ( ! is_null($ret = $this->SendCommand(MPD_CMD_VOLUME,$modifier))) $this->volume = $newVol;
    if ( $this->debugging ) echo "mpd->SetVolume() / return\n";
    return $ret;
    /* GetDir()
    * Retrieves a database directory listing of the <dir> directory and places the results into
    * a multidimensional array. If no directory is specified, the directory listing is at the
    * base of the MPD music path.
    function GetDir($dir = "") {
    if ( $this->debugging ) echo "mpd->GetDir()\n";
    $resp = $this->SendCommand(MPD_CMD_LSDIR,$dir);
    $dirlist = $this->_parseFileListResponse($resp);
    if ( $this->debugging ) echo "mpd->GetDir() / return ".print_r($dirlist)."\n";
    return $dirlist;
    /* PLAdd()
    * Adds each track listed in a single-dimensional <trackArray>, which contains filenames
    * of tracks to add, to the end of the playlist. This is used to add many, many tracks to
    * the playlist in one swoop.
    function PLAddBulk($trackArray) {
    if ( $this->debugging ) echo "mpd->PLAddBulk()\n";
    $num_files = count($trackArray);
    for ( $i = 0; $i < $num_files; $i++ ) {
    $this->QueueCommand(MPD_CMD_PLADD,$trackArray[$i]);
    $resp = $this->SendCommandQueue();
    $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->PLAddBulk() / return\n";
    return $resp;
    /* PLAdd()
    * Adds the file <file> to the end of the playlist. <file> must be a track in the MPD database.
    function PLAdd($fileName) {
    if ( $this->debugging ) echo "mpd->PLAdd()\n";
    if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLADD,$fileName))) $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->PLAdd() / return\n";
    return $resp;
    /* PLMoveTrack()
    * Moves track number <origPos> to position <newPos> in the playlist. This is used to reorder
    * the songs in the playlist.
    function PLMoveTrack($origPos, $newPos) {
    if ( $this->debugging ) echo "mpd->PLMoveTrack()\n";
    if ( ! is_numeric($origPos) ) {
    $this->errStr = "PLMoveTrack(): argument 1 must be numeric";
    return NULL;
    if ( $origPos < 0 or $origPos > $this->playlist_count ) {
    $this->errStr = "PLMoveTrack(): argument 1 out of range";
    return NULL;
    if ( $newPos < 0 ) $newPos = 0;
    if ( $newPos > $this->playlist_count ) $newPos = $this->playlist_count;
    if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLMOVETRACK,$origPos,$newPos))) $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->PLMoveTrack() / return\n";
    return $resp;
    /* PLShuffle()
    * Randomly reorders the songs in the playlist.
    function PLShuffle() {
    if ( $this->debugging ) echo "mpd->PLShuffle()\n";
    if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLSHUFFLE))) $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->PLShuffle() / return\n";
    return $resp;
    /* PLLoad()
    * Retrieves the playlist from <file>.m3u and loads it into the current playlist.
    function PLLoad($file) {
    if ( $this->debugging ) echo "mpd->PLLoad()\n";
    if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLLOAD,$file))) $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->PLLoad() / return\n";
    return $resp;
    /* PLSave()
    * Saves the playlist to <file>.m3u for later retrieval. The file is saved in the MPD playlist
    * directory.
    function PLSave($file) {
    if ( $this->debugging ) echo "mpd->PLSave()\n";
    $resp = $this->SendCommand(MPD_CMD_PLSAVE,$file);
    if ( $this->debugging ) echo "mpd->PLSave() / return\n";
    return $resp;
    /* PLClear()
    * Empties the playlist.
    function PLClear() {
    if ( $this->debugging ) echo "mpd->PLClear()\n";
    if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLCLEAR))) $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->PLClear() / return\n";
    return $resp;
    /* PLRemove()
    * Removes track <id> from the playlist.
    function PLRemove($id) {
    if ( $this->debugging ) echo "mpd->PLRemove()\n";
    if ( ! is_numeric($id) ) {
    $this->errStr = "PLRemove() : argument 1 must be a numeric value";
    return NULL;
    if ( ! is_null($resp = $this->SendCommand(MPD_CMD_PLREMOVE,$id))) $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->PLRemove() / return\n";
    return $resp;
    /* SetRepeat()
    * Enables 'loop' mode -- tells MPD continually loop the playlist. The <repVal> parameter
    * is either 1 (on) or 0 (off).
    function SetRepeat($repVal) {
    if ( $this->debugging ) echo "mpd->SetRepeat()\n";
    $rpt = $this->SendCommand(MPD_CMD_REPEAT,$repVal);
    $this->repeat = $repVal;
    if ( $this->debugging ) echo "mpd->SetRepeat() / return\n";
    return $rpt;
    /* SetRandom()
    * Enables 'randomize' mode -- tells MPD to play songs in the playlist in random order. The
    * <rndVal> parameter is either 1 (on) or 0 (off).
    function SetRandom($rndVal) {
    if ( $this->debugging ) echo "mpd->SetRandom()\n";
    $resp = $this->SendCommand(MPD_CMD_RANDOM,$rndVal);
    $this->random = $rndVal;
    if ( $this->debugging ) echo "mpd->SetRandom() / return\n";
    return $resp;
    /* Shutdown()
    * Shuts down the MPD server (aka sends the KILL command). This closes the current connection,
    * and prevents future communication with the server.
    function Shutdown() {
    if ( $this->debugging ) echo "mpd->Shutdown()\n";
    $resp = $this->SendCommand(MPD_CMD_SHUTDOWN);
    $this->connected = FALSE;
    unset($this->mpd_version);
    unset($this->errStr);
    unset($this->mpd_sock);
    if ( $this->debugging ) echo "mpd->Shutdown() / return\n";
    return $resp;
    /* DBRefresh()
    * Tells MPD to rescan the music directory for new tracks, and to refresh the Database. Tracks
    * cannot be played unless they are in the MPD database.
    function DBRefresh() {
    if ( $this->debugging ) echo "mpd->DBRefresh()\n";
    $resp = $this->SendCommand(MPD_CMD_REFRESH);
    // Update local variables
    $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->DBRefresh() / return\n";
    return $resp;
    /* Play()
    * Begins playing the songs in the MPD playlist.
    function Play() {
    if ( $this->debugging ) echo "mpd->Play()\n";
    if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PLAY) )) $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->Play() / return\n";
    return $rpt;
    /* Stop()
    * Stops playing the MPD.
    function Stop() {
    if ( $this->debugging ) echo "mpd->Stop()\n";
    if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_STOP) )) $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->Stop() / return\n";
    return $rpt;
    /* Pause()
    * Toggles pausing on the MPD. Calling it once will pause the player, calling it again
    * will unpause.
    function Pause() {
    if ( $this->debugging ) echo "mpd->Pause()\n";
    if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PAUSE) )) $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->Pause() / return\n";
    return $rpt;
    /* SeekTo()
    * Skips directly to the <idx> song in the MPD playlist.
    function SkipTo($idx) {
    if ( $this->debugging ) echo "mpd->SkipTo()\n";
    if ( ! is_numeric($idx) ) {
    $this->errStr = "SkipTo() : argument 1 must be a numeric value";
    return NULL;
    if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PLAY,$idx))) $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->SkipTo() / return\n";
    return $idx;
    /* SeekTo()
    * Skips directly to a given position within a track in the MPD playlist. The <pos> argument,
    * given in seconds, is the track position to locate. The <track> argument, if supplied is
    * the track number in the playlist. If <track> is not specified, the current track is assumed.
    function SeekTo($pos, $track = -1) {
    if ( $this->debugging ) echo "mpd->SeekTo()\n";
    if ( ! is_numeric($pos) ) {
    $this->errStr = "SeekTo() : argument 1 must be a numeric value";
    return NULL;
    if ( ! is_numeric($track) ) {
    $this->errStr = "SeekTo() : argument 2 must be a numeric value";
    return NULL;
    if ( $track == -1 ) {
    $track = $this->current_track_id;
    if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_SEEK,$track,$pos))) $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->SeekTo() / return\n";
    return $pos;
    /* Next()
    * Skips to the next song in the MPD playlist. If not playing, returns an error.
    function Next() {
    if ( $this->debugging ) echo "mpd->Next()\n";
    if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_NEXT))) $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->Next() / return\n";
    return $rpt;
    /* Previous()
    * Skips to the previous song in the MPD playlist. If not playing, returns an error.
    function Previous() {
    if ( $this->debugging ) echo "mpd->Previous()\n";
    if ( ! is_null($rpt = $this->SendCommand(MPD_CMD_PREV))) $this->RefreshInfo();
    if ( $this->debugging ) echo "mpd->Previous() / return\n";
    return $rpt;
    /* Search()
    * Searches the MPD database. The search <type> should be one of the following:
    * MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM
    * The search <string> is a case-insensitive locator string. Anything that contains
    * <string> will be returned in the results.
    function Search($type,$string) {
    if ( $this->debugging ) echo "mpd->Search()\n";
    if ( $type != MPD_SEARCH_ARTIST and
    $type != MPD_SEARCH_ALBUM and
    $type != MPD_SEARCH_TITLE ) {
    $this->errStr = "mpd->Search(): invalid search type";
    return NULL;
    } else {
    if ( is_null($resp = $this->SendCommand(MPD_CMD_SEARCH,$type,$string))) return NULL;
    $searchlist = $this->_parseFileListResponse($resp);
    if ( $this->debugging ) echo "mpd->Search() / return ".print_r($searchlist)."\n";
    return $searchlist;
    /* Find()
    * Find() looks for exact matches in the MPD database. The find <type> should be one of
    * the following:
    * MPD_SEARCH_ARTIST, MPD_SEARCH_TITLE, MPD_SEARCH_ALBUM
    * The find <string> is a case-insensitive locator string. Anything that exactly matches
    * <string> will be returned in the results.
    function Find($type,$string) {
    if ( $this->debugging ) echo "mpd->Find()\n";
    if ( $type != MPD_SEARCH_ARTIST and
    $type != MPD_SEARCH_ALBUM and
    $type != MPD_SEARCH_TITLE ) {
    $this->errStr = "mpd->Find(): invalid find type";
    return NULL;
    } else {
    if ( is_null($resp = $this->SendCommand(MPD_CMD_FIND,$type,$string))) return NULL;
    $searchlist = $this->_parseFileListResponse($resp);
    if ( $this->debugging ) echo "mpd->Find() / return ".print_r($searchlist)."\n";
    return $searchlist;
    /* Disconnect()
    * Closes the connection to the MPD server.
    function Disconnect() {
    if ( $this->debugging ) echo "mpd->Disconnect()\n";
    fclose($this->mpd_sock);
    $this->connected = FALSE;
    unset($this->mpd_version);
    unset($this->errStr);
    unset($this->mpd_sock);
    /* GetArtists()
    * Returns the list of artists in the database in an associative array.
    function GetArtists() {
    if ( $this->debugging ) echo "mpd->GetArtists()\n";
    if ( is_null($resp = $this->SendCommand(MPD_CMD_TABLE, MPD_TBL_ARTIST))) return NULL;
    $arArray = array();
    $arLine = strtok($resp,"\n");
    $arName = "";
    $arCounter = -1;
    while ( $arLine ) {
    list ( $element, $value ) = split(": ",$arLine);
    if ( $element == "Artist" ) {
    $arCounter++;
    $arName = $value;
    $arArray[$arCounter] = $arName;
    $arLine = strtok("\n");
    if ( $this->debugging ) echo "mpd->GetArtists()\n";
    return $arArray;
    /* GetAlbums()
    * Returns the list of albums in the database in an associative array. Optional parameter
    * is an artist Name which will list all albums by a particular artist.
    function GetAlbums( $ar = NULL) {
    if ( $this->debugging ) echo "mpd->GetAlbums()\n";
    if ( is_null($resp = $this->SendCommand(MPD_CMD_TABLE, MPD_TBL_ALBUM, $ar ))) return NULL;
    $alArray = array();
    $alLine = strtok($resp,"\n");
    $alName = "";
    $alCounter = -1;
    while ( $alLine ) {
    list ( $element, $value ) = split(": ",$alLine);
    if ( $element == "Album" ) {
    $alCounter++;
    $alName = $value;
    $alArray[$alCounter] = $alName;
    $alLine = strtok("\n");
    if ( $this->debugging ) echo "mpd->GetAlbums()\n";
    return $alArray;
    //***************************** INTERNAL FUNCTIONS ******************************//
    /* _computeVersionValue()
    * Computes a compatibility value from a version string
    function _computeVersionValue($verStr) {
    list ($ver_maj, $ver_min, $ver_rel ) = split("\.",$verStr);
    return ( 100 * $ver_maj ) + ( 10 * $ver_min ) + ( $ver_rel );
    /* _checkCompatibility()
    * Check MPD command compatibility against our internal table. If there is no version
    * listed in the table, allow it by default.
    function _checkCompatibility($cmd) {
    // Check minimum compatibility
    $req_ver_low = $this->COMPATIBILITY_MIN_TBL[$cmd];
    $req_ver_hi = $this->COMPATIBILITY_MAX_TBL[$cmd];
    $mpd_ver = $this->_computeVersionValue($this->mpd_version);
    if ( $req_ver_low ) {
    $req_ver = $this->_computeVersionValue($req_ver_low);
    if ( $mpd_ver < $req_ver ) {
    $this->errStr = "Command '$cmd' is not compatible with this version of MPD, version ".$req_ver_low." required";
    return FALSE;
    // Check maxmum compatibility -- this will check for deprecations
    if ( $req_ver_hi ) {
    $req_ver = $this->_computeVersionValue($req_ver_hi);
    if ( $mpd_ver > $req_ver ) {
    $this->errStr = "Command '$cmd' has been deprecated in this version of MPD.";
    return FALSE;
    return TRUE;
    /* _parseFileListResponse()
    * Builds a multidimensional array with MPD response lists.
    * NOTE: This function is used internally within the class. It should not be used.
    function _parseFileListResponse($resp) {
    if ( is_null($resp) ) {
    return NULL;
    } else {
    $plistArray = array();
    $plistLine = strtok($resp,"\n");
    $plistFile = "";
    $plCounter = -1;
    while ( $plistLine ) {
    list ( $element, $value ) = split(": ",$plistLine);
    if ( $element == "file" ) {
    $plCounter++;
    $plistFile = $value;
    $plistArray[$plCounter]["file"] = $plistFile;
    } else {
    $plistArray[$plCounter][$element] = $value;
    $plistLine = strtok("\n");
    return $plistArray;
    /* RefreshInfo()
    * Updates all class properties with the values from the MPD server.
    * NOTE: This function is automatically called upon Connect() as of v1.1.
    function RefreshInfo() {
    // Get the Server Statistics
    $statStr = $this->SendCommand(MPD_CMD_STATISTICS);
    if ( !$statStr ) {
    return NULL;
    } else {
    $stats = array();
    $statLine = strtok($statStr,"\n");
    while ( $statLine ) {
    list ( $element, $value ) = split(": ",$statLine);
    $stats[$element] = $value;
    $statLine = strtok("\n");
    // Get the Server Status
    $statusStr = $this->SendCommand(MPD_CMD_STATUS);
    if ( ! $statusStr ) {
    return NULL;
    } else {
    $status = array();
    $statusLine = strtok($statusStr,"\n");
    while ( $statusLine ) {
    list ( $element, $value ) = split(": ",$statusLine);
    $status[$element] = $value;
    $statusLine = strtok("\n");
    // Get the Playlist
    $plStr = $this->SendCommand(MPD_CMD_PLLIST);
    $this->playlist = $this->_parseFileListResponse($plStr);
    $this->playlist_count = count($this->playlist);
    // Set Misc Other Variables
    $this->state = $status['state'];
    if ( ($this->state == MPD_STATE_PLAYING) || ($this->state == MPD_STATE_PAUSED) ) {
    $this->current_track_id = $status['song'];
    list ($this->current_track_position, $this->current_track_length ) = split(":",$status['time']);
    } else {
    $this->current_track_id = -1;
    $this->current_track_position = -1;
    $this->current_track_length = -1;
    $this->repeat = $status['repeat'];
    $this->random = $status['random'];
    $this->db_last_refreshed = $stats['db_update'];
    $this->volume = $status['volume'];
    $this->uptime = $stats['uptime'];
    $this->playtime = $stats['playtime'];
    $this->num_songs_played = $stats['songs_played'];
    $this->num_artists = $stats['num_artists'];
    $this->num_songs = $stats['num_songs'];
    $this->num_albums = $stats['num_albums'];
    return TRUE;
    /* ------------------ DEPRECATED METHODS -------------------*/
    /* GetStatistics()
    * Retrieves the 'statistics' variables from the server and tosses them into an array.
    * NOTE: This function really should not be used. Instead, use $this->[variable]. The function
    * will most likely be deprecated in future releases.
    function GetStatistics() {
    if ( $this->debugging ) echo "mpd->GetStatistics()\n";
    $stats = $this->SendCommand(MPD_CMD_STATISTICS);
    if ( !$stats ) {
    return NULL;
    } else {
    $statsArray = array();
    $statsLine = strtok($stats,"\n");
    while ( $statsLine ) {
    list ( $element, $value ) = split(": ",$statsLine);
    $statsArray[$element] = $value;
    $statsLine = strtok("\n");
    if ( $this->debugging ) echo "mpd->GetStatistics() / return: " . print_r($statsArray) ."\n";
    return $statsArray;
    /* GetStatus()
    * Retrieves the 'status' variables from the server and tosses them into an array.
    * NOTE: This function really should not be used. Instead, use $this->[variable]. The function
    * will most likely be deprecated in future releases.
    function GetStatus() {
    if ( $this->debugging ) echo "mpd->GetStatus()\n";
    $status = $this->SendCommand(MPD_CMD_STATUS);
    if ( ! $status ) {
    return NULL;
    } else {
    $statusArray = array();
    $statusLine = strtok($status,"\n");
    while ( $statusLine ) {
    list ( $element, $value ) = split(": ",$statusLine);
    $statusArray[$element] = $value;
    $statusLine = strtok("\n");
    if ( $this->debugging ) echo "mpd->GetStatus() / return: " . print_r($statusArray) ."\n";
    return $statusArray;
    /* GetVolume()
    * Retrieves the mixer volume from the server.
    * NOTE: This function really should not be used. Instead, use $this->volume. The function
    * will most likely be deprecated in future releases.
    function GetVolume() {
    if ( $this->debugging ) echo "mpd->GetVolume()\n";
    $volLine = $this->SendCommand(MPD_CMD_STATUS);
    if ( ! $volLine ) {
    return NULL;
    } else {
    list ($vol) = sscanf($volLine,"volume: %d");
    if ( $this->debugging ) echo "mpd->GetVolume() / return: $vol\n";
    return $vol;
    /* GetPlaylist()
    * Retrieves the playlist from the server and tosses it into a multidimensional array.
    * NOTE: This function really should not be used. Instead, use $this->playlist. The function
    * will most likely be deprecated in future releases.
    function GetPlaylist() {
    if ( $this->debugging ) echo "mpd->GetPlaylist()\n";
    $resp = $this->SendCommand(MPD_CMD_PLLIST);
    $playlist = $this->_parseFileListResponse($resp);
    if ( $this->debugging ) echo "mpd->GetPlaylist() / return ".print_r($playlist)."\n";
    return $playlist;
    /* ----------------- Command compatibility tables --------------------- */
    var $COMPATIBILITY_MIN_TBL = array(
    MPD_CMD_SEEK => "0.9.1" ,
    MPD_CMD_PLMOVE => "0.9.1" ,
    MPD_CMD_RANDOM => "0.9.1" ,
    MPD_CMD_PLSWAPTRACK => "0.9.1" ,
    MPD_CMD_PLMOVETRACK => "0.9.1" ,
    MPD_CMD_PASSWORD => "0.10.0" ,
    MPD_CMD_SETVOL => "0.10.0"
    var $COMPATIBILITY_MAX_TBL = array(
    MPD_CMD_VOLUME => "0.10.0"
    } // ---------------------------- end of class ------------------------------
    ?>
    and the HTML output:
    <HTML>
    <style type="text/css"><!-- .defaultText { font-family: Arial, Helvetica, sans-serif; font-size: 9pt; font-style: normal; font-weight: normal; color: #111111} .err { color: #DD3333 } --></style>
    <BODY class="defaultText">
    connected == FALSE ) {
    echo "Error Connecting: " . $myMpd->errStr;
    } else {
    switch ($_REQUEST[m]) {
    case "add":
    if ( is_null($myMpd->PLAdd($_REQUEST[filename])) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
    break;
    case "rem":
    if ( is_null($myMpd->PLRemove($_REQUEST[id])) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
    break;
    case "setvol":
    if ( is_null($myMpd->SetVolume($_REQUEST[vol])) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
    break;
    case "play":
    if ( is_null($myMpd->Play()) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
    break;
    case "stop":
    if ( is_null($myMpd->Stop()) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
    break;
    case "pause":
    if ( is_null($myMpd->Pause()) ) echo "<SPAN CLASS=err>ERROR: " .$myMpd->errStr."</SPAN>";
    break;
    default:
    break;
    ?>
    <DIV ALIGN=CENTER>[ <A HREF="<? echo $_SERVER[PHP_SELF] ?>">Refresh Page</A> ]</DIV>
    <HR>
    <B>Connected to MPD Version mpd_version ?> at host ?>:port ?></B><BR>
    State:
    state) {
    case MPD_STATE_PLAYING: echo "MPD is Playing [<A HREF='".$_SERVER[PHP_SELF]."?m=pause'>Pause</A>] [<A HREF='".$_SERVER[PHP_SELF]."?m=stop'>Stop</A>]"; break;
    case MPD_STATE_PAUSED: echo "MPD is Paused [<A HREF='".$_SERVER[PHP_SELF]."?m=pause'>Unpause</A>]"; break;
    case MPD_STATE_STOPPED: echo "MPD is Stopped [<A HREF='".$_SERVER[PHP_SELF]."?m=play'>Play</A>]"; break;
    default: echo "(Unknown State!)"; break;
    ?>
    <BR>
    Volume: volume ?> [ <A HREF='<? echo $_SERVER[PHP_SELF] ?>?m=setvol&vol=0'>0</A> | <A HREF='<? echo $_SERVER[PHP_SELF] ?>?m=setvol&vol=25'>25</A> | <A HREF='<? echo $_SERVER[PHP_SELF] ?>?m=setvol&vol=75'>75</A> | <A HREF='<? echo $_SERVER[PHP_SELF] ?>?m=setvol&vol=100'>100</A> ]<BR>
    Uptime: uptime) ?><BR>
    Playtime: playtime) ?><BR>
    state == MPD_STATE_PLAYING or $myMpd->state == MPD_STATE_PAUSED ) { ?>
    Currently Playing: playlist[$myMpd->current_track_id]['Artist']." - ".$myMpd->playlist[$myMpd->current_track_id]['Title'] ?><BR>
    Track Position: current_track_position."/".$myMpd->current_track_length." (".(round(($myMpd->current_track_position/$myMpd->current_track_length),2)*100)."%)" ?><BR>
    Playlist Position: current_track_id+1)."/".$myMpd->playlist_count." (".(round((($myMpd->current_track_id+1)/$myMpd->playlist_count),2)*100)."%)" ?><BR>
    <HR>
    <B>Playlist - Total: playlist_count ?> tracks (Click to Remove)</B><BR>
    playlist) ) echo "ERROR: " .$myMpd->errStr."\n";
    else {
    foreach ($myMpd->playlist as $id => $entry) {
    echo ( $id == $myMpd->current_track_id ? "<B>" : "" ) . ($id+1) . ". <A HREF='".$_SERVER[PHP_SELF]."?m=rem&id=".$id."'>".$entry['Artist']." - ".$entry['Title']."</A>".( $id == $myMpd->current_track_id ? "</B>" : "" )."<BR>\n";
    ?>
    <HR>
    <B>Sample Search for the String 'U2' (Click to Add to Playlist)</B><BR>
    Search(MPD_SEARCH_ARTIST,'U2');
    if ( is_null($sl) ) echo "ERROR: " .$myMpd->errStr."\n";
    else {
    foreach ($sl as $id => $entry) {
    echo ($id+1) . ": <A HREF='".$_SERVER[PHP_SELF]."?m=add&filename=".urlencode($entry['file'])."'>".$entry['Artist']." - ".$entry['Title']."</A><BR>\n";
    if ( count($sl) == 0 ) echo "<I>No results returned from search.</I>";
    // Example of how you would use Bulk Add features of MPD
    // $myarray = array();
    // $myarray[0] = "ACDC - Thunderstruck.mp3";
    // $myarray[1] = "ACDC - Back In Black.mp3";
    // $myarray[2] = "ACDC - Hells Bells.mp3";
    // if ( is_null($myMpd->PLAddBulk($myarray)) ) echo "ERROR: ".$myMpd->errStr."\n";
    ?>
    <HR>
    <B>Artist List</B><BR>
    GetArtists()) ) echo "ERROR: " .$myMpd->errStr."\n";
    else {
    while(list($key, $value) = each($ar) ) {
    echo ($key+1) . ". " . $value . "<BR>";
    $myMpd->Disconnect();
    // Used to make number of seconds perty.
    function secToTimeStr($secs) {
    $days = ($secs%604800)/86400;
    $hours = (($secs%604800)%86400)/3600;
    $minutes = ((($secs%604800)%86400)%3600)/60;
    $seconds = (((($secs%604800)%86400)%3600)%60);
    if (round($days)) $timestring .= round($days)."d ";
    if (round($hours)) $timestring .= round($hours)."h ";
    if (round($minutes)) $timestring .= round($minutes)."m";
    if (!round($minutes)&&!round($hours)&&!round($days)) $timestring.=" ".round($seconds)."s";
    return $timestring;
    ?>
    </BODY></HTML>
    As you can see it doesn't seem to understand the pointer operator. Do I have to enable anything in the PHP config files or something?

    It's set up correctly. Also, it does parse PHP, just not after the arrow.
    Here is my php.ini:
    ; With mbstring support this will automatically be converted into the encoding
    ; given by corresponding encode setting. When empty mbstring.internal_encoding
    ; is used. For the decode settings you can distinguish between motorola and
    ; intel byte order. A decode setting cannot be empty.
    ; http://php.net/exif.encode-unicode
    ;exif.encode_unicode = ISO-8859-15
    ; http://php.net/exif.decode-unicode-motorola
    ;exif.decode_unicode_motorola = UCS-2BE
    ; http://php.net/exif.decode-unicode-intel
    ;exif.decode_unicode_intel = UCS-2LE
    ; http://php.net/exif.encode-jis
    ;exif.encode_jis =
    ; http://php.net/exif.decode-jis-motorola
    ;exif.decode_jis_motorola = JIS
    ; http://php.net/exif.decode-jis-intel
    ;exif.decode_jis_intel = JIS
    [Tidy]
    ; The path to a default tidy configuration file to use when using tidy
    ; http://php.net/tidy.default-config
    ;tidy.default_config = /usr/local/lib/php/default.tcfg
    ; Should tidy clean and repair output automatically?
    ; WARNING: Do not use this option if you are generating non-html content
    ; such as dynamic images
    ; http://php.net/tidy.clean-output
    tidy.clean_output = Off
    [soap]
    ; Enables or disables WSDL caching feature.
    ; http://php.net/soap.wsdl-cache-enabled
    soap.wsdl_cache_enabled=1
    ; Sets the directory name where SOAP extension will put cache files.
    ; http://php.net/soap.wsdl-cache-dir
    soap.wsdl_cache_dir="/tmp"
    ; (time to live) Sets the number of second while cached file will be used
    ; instead of original one.
    ; http://php.net/soap.wsdl-cache-ttl
    soap.wsdl_cache_ttl=86400
    ; Sets the size of the cache limit. (Max. number of WSDL files to cache)
    soap.wsdl_cache_limit = 5
    [sysvshm]
    ; A default size of the shared memory segment
    ;sysvshm.init_mem = 10000
    [ldap]
    ; Sets the maximum number of open links or -1 for unlimited.
    ldap.max_links = -1
    [mcrypt]
    ; For more information about mcrypt settings see http://php.net/mcrypt-module-open
    ; Directory where to load mcrypt algorithms
    ; Default: Compiled in into libmcrypt (usually /usr/local/lib/libmcrypt)
    ;mcrypt.algorithms_dir=
    ; Directory where to load mcrypt modes
    ; Default: Compiled in into libmcrypt (usually /usr/local/lib/libmcrypt)
    ;mcrypt.modes_dir=
    [dba]
    ;dba.default_handler=
    ; Local Variables:
    ; tab-width: 4
    ; End:
    Last edited by BaconPie (2010-11-04 20:11:33)

  • Two remote objects calls on the same php class

    Hi to all,
           I've encountered a strange issue while developing with remote objects.
    I've a mxml component with an init() method inside which is called by a menu.
    When the init() method is called it makes 7 remote object calls which are bound to some components' dataprovider.
    Among this calls I've got 2 remote object which refer to the same remote class. This because I have to call the class twice and the bind the result to two different combobox. Below you find the code:
    <mx:RemoteObject id="myFile" source="myRemoteClass" destination="amfphp"  showBusyCursor="true" makeObjectsBindable="true" fault="traceFault(event)"/>
    <mx:RemoteObject id="myXls"  source="myRemoteClass" destination="amfphp"  showBusyCursor="true" makeObjectsBindable="true" fault="traceFault(event)"/>
    in the init function I make this calls:
    myFile.listDir("dir_1")
    myXls.listDir("dir_2")
    then in the mxml code I bound the result of myFile to combobox1 and the result of myXls on combobox2.
    The problem arise when I call the myXls' listDir method. When I call it I receive the following error:
    code:
    Client.Error.DeliveryInDoubt
    Message:
    Channel disconnected
    Detail:
    Channel disconnected before an acknowledgement was received
    The strange thing is that not only the myXls object returns this error, but also all the other 6 remote object return the same error above.
    I'm not sure, but I guess that the error could be caused by the two remote object which call the same php remote class. If I comment one of the two calls everything works fine.
    Do you have any suggestion about?
    Thanks!!
    Bye
    Luke

    Hi Jan.
    1) We have the 2 VO, each with 3 rows to fill in data. What I mean is that when i just fill in all the fields for the first row of the first VO, and the value of one of these fields is bigger than 50, then after the exception is thrown and the message is displayed, the fields for the first VO are duplicated and shown in the second VO as if the user had inserted them.
    2) We tried yesterday the validateEntity and a Method and Atributte Validator approaches after reading that white paper with the same results.
    The validation is correctly done using any of the those methods.
    I will try to reproduce this issue with the HR schema.
    Thanks in advance once again.

  • I need help getting my local testing server to work - PHP/MySQL

    Hello,
    I am using DW CS5 and have installed XAMPP for my Server/PHP/DB package (which is the same as my live site).
    I have gone thru every tuitorial and all information on this subject, and unfortunately I can't get the server set up correct. Other than my page not showing in a browser (or live view) when I try to view it, DW just says: "Dynamically-related files could not be resolved because the site definition is not correct for this server" when I have index.php open and try to find the files.
    One major question is I am unsure of what folder to have as the root folder of the site, which has a public_htlm directory and www directory - or do I just use the main folder they are both located in as the root folder?
    (Not to get too deep with this first question, but I also looked at the error log file in Apache c:\xampp\apache\logs\error.log and it is not finding the following:
    [Tue Oct 09 14:26:38.573504 2012] [:error] [pid 3100:tid 1488] [client ::1:56261] script 'C:/xampp/htdocs/BusinessTube/index_e5pebna8e.php' not found or unable to stat]
    I'm guessing that the file "index_e5pebna8e.php" is a cached version of the file generated by index.php - but I'm unsure why it is not being 'found'.)
    Second question is about having to set the php.ini file to listen to port 88 as this computer also has IIS installed. I have done this, and it works with a local project directly from NetBeans (which I have to use for a PHP development class). How will this change my DW site definitions? I'm assuming that anywhere I would have localhost I will now need to have localhost:88 but once again I'm not sure.
    I am eager to get this site working locally so I can start using the new PHP skills I'm learning - any help will be GREATLY appreciated.
    Kirk

    You're getting mixed up over the meaning of public_html.
    Most hosting companies that offer PHP use the Apache web server, which has a single server root folder called htdocs. XAMPP also uses Apache, so c:/xampp/htdocs is the XAMPP server root, and its URL is http://localhost/.
    Although Apache has only one server root, virtual hosts make it possible to run multiple websites on the same server. Each virtual host is located in a separate folder that acts as the site root. It's common for this folder to be called public_html. What bregent was describing was the location of the site root on your remote server. The name of the site root in your local testing setup can be whatever you decide to call it.
    When learning to use PHP, most people use a subfolder of the Apache server root because it doesn't require further configuration. However, once you're working with real sites, it's normal to set up a virtual host for each one. I create all my virtual hosts in a folder called C:/vhosts. So for example, I might have one in C:/vhosts/site1. In the virtual hosts configuration file, I designate C:/vhosts/site1 as the root folder for a virtual host called site1, which can then be accessed as http://site1/.
    The only reason I might have a folder called public_html is if I designated C:/vhosts/site1/public_html as the site root.
    I hope that's clear. Once you understand the principle of virtual hosts, the concept of the site (or server) root becomes obvious, but it can be difficult to explain. I remember it took me a while before the concept sank in.

  • FormToEmail.php is not working correctly

    When you press the submit button on my form nothing happens. Please help!!!!! 
    Here is my form HTML:
        <h1>Request A Life Insurance Quote    </h1>
        <table border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="590" valign="top"><form id="FrmLifeQuote" name="FrmLifeQuote" method="post" action="formmail.php">
              <fieldset class="text">
            <legend></legend>
            <p><span id="sprytextfield1">
                <label for="First_Name">First Name:</label>
                <input type="text" name="First_Name" id="First_Name" tabindex="10" />
                <span class="textfieldRequiredMsg">[required]</span></span></p>
              <p><span id="sprytextfield2">
                <label for="name">Last Name:</label>
                <input type="text" name="name" id="name" tabindex="20"/>
                <span class="textfieldRequiredMsg"> [required]</span></span></p>
              <p><span id="sprytextfield3">
              <label for="Email">Email Address:</label>
              <input type="text" name="Email" id="Email" tabindex="30" />
              <span class="textfieldRequiredMsg">[required]</span></span></p>
              <p><span id="sprytextfield4">
              <label for="PhoneNumber">Phone Number:</label>
              <input type="text" name="PhoneNumber" id="PhoneNumber" tabindex="40" />
              <span class="textfieldRequiredMsg">[required]</span></span></p>
              </fieldset>
              <fieldset>
               <p>
              <legend class="text"></legend>          
               <p>Birthday      <span id="spryselect1">
                <label for="Month"></label>
                <select name="Month" id="Month" tabindex="50">
                <option value="MM">MM</option>
                <option value="01">01</option>
                <option value="02">02</option>
                <option value="03">03</option>
                <option value="04">04</option>
                <option value="05">05</option>
                <option value="06">06</option>
                <option value="07">07</option>
                <option value="08">08</option>
                <option value="09">09</option>
                <option value="10">10</option>
                <option value="11">11</option>
                <option value="12">12</option>
              </select>
              <label for="Day"></label>
              <select name="Day" id="Day" tabindex="51">
                <option value="DD">DD</option>
                <option value="01">01</option>
                <option value="02">02</option>
                <option value="03">03</option>
                <option value="04">04</option>
                <option value="05">05</option>
                <option value="06">06</option>
                <option value="07">07</option>
                <option value="08">08</option>
                <option value="09">09</option>
                <option value="10">10</option>
                <option value="11">11</option>
                <option value="12">12</option>
                <option value="13">13</option>
                <option value="14">14</option>
                <option value="15">15</option>
                <option value="16">16</option>
                <option value="17">17</option>
                <option value="18">18</option>
                <option value="19">19</option>
                <option value="20">20</option>
                <option value="21">21</option>
                <option value="22">22</option>
                <option value="23">23</option>
                <option value="24">24</option>
                <option value="25">25</option>
                <option value="26">26</option>
                <option value="27">27</option>
                <option value="28">28</option>
                <option value="29">29</option>
                <option value="30">30</option>
                <option value="31">31</option>
                </select>
                <span class="selectRequiredMsg">Please select an item.</span></span><span id="sprytextfield5">
                <label for="Year"></label>
                <input name="Year" type="text" id="Year" tabindex="52" value="YYYY" size="8" />
                <span class="textfieldRequiredMsg">[required]</span></span></p>
              <p><span id="spryselect2">
                <label for="Gender">Gender:</label>
                <select name="Gender" id="Gender" tabindex="60">
                  <option value="Select">Select</option>
                  <option value="Female">Female</option>
                  <option value="Male">Male</option>
                </select>
                <span class="selectRequiredMsg">Please select an item.</span></span><span class="textfieldRequiredMsg">[required]</span></p>
              <p class="text">
                <label for="CoverageAmount">Coverage Amount:</label>
                <input type="text" name="CoverageAmount" id="CoverageAmount" tabindex="70" />
                <span class="textfieldRequiredMsg">[required]</span></p>
              <p>
              <label for="CoverageLength">Coverage Length:</label>
              <select name="CoverageLength" class="text" id="CoverageLength" tabindex="80">
                <option value="Select" selected="selected">Select</option>
                <option value="10 Year">10 Year</option>
                <option value="15 Year">15 Year</option>
                <option value="20 Year">20 Year</option>
                <option value="25 Year">25 Year</option>
                <option value="30 Year">30 Year</option>
                <option value="UL">UL</option>
              </select>
              <span class="textfieldRequiredMsg">[required]</span></p>
              <p class="text">
              <label for="TobaccoUse">Tobacco Use:</label>
              <select name="TobaccoUse" id="TobaccoUse" tabindex="80">
                <option value="Select" selected="selected">Select</option>
                <option value="None">None</option>
                <option value="Cigarette">Cigarette</option>
                <option value="Cigar">Cigar</option>
                <option value="Pipe">Pipe</option>
                <option value="Chewing Tobacco">Chewing Tobacco</option>
                <option value="Nicotine Patch">Nicotine Patch</option>
                <option value="Gum">Gum</option>
              </select>
              <span class="textfieldRequiredMsg">[required]</span></p>
              <p class="text">Have you ever been treated for Cancer, Heart Disease, Stroke, Diabetes, High Blood Pressure, Alcohol or Drug Abuse, Depression, Asthma, or any other similar conditions?                    <br />         
              <p>
                <label>
                  <input type="radio" name="RadioGroup1" value="Yes" id="RadioGroup1_0" />
                  Yes</label>
                <br />
                <label>
                  <input type="radio" name="RadioGroup1" value="No" id="RadioGroup1_1" />
                  No</label>
                <br />
              </p>
              <p class="text">Do you have more than 2 citations for moving violations in the past three years?          
              <p>
                <label>
                  <input type="radio" name="RadioGroup2" value="Yes" id="RadioGroup2_0" />
                  Yes</label>
                <br />
                <label>
                  <input type="radio" name="RadioGroup2" value="No" id="RadioGroup2_1" />
                  No</label>
                <br />
              </p>
              <p class="text">Do you do any hazardous activities?
              <p>
                <label>
                  <input type="radio" name="RadioGroup3" value="Yes" id="RadioGroup3_0" />
                  Yes</label>
                <br />
                <label>
                  <input type="radio" name="RadioGroup3" value="No" id="RadioGroup3_1" />
                  No</label>
                <br />
              </p>
              <p class="text">
                <input type="submit" name="Submit" id="Submit" value="Request A Life Insurance Quote" tabindex="130" />
                <form action="FormToEmail.php">
            </form></td>
          </tr>
        </table>
        <h1><script type="text/javascript">
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "none", {validateOn:["blur", "change"]});
    var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
    var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "email");
    var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4", "phone_number");
    var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1");
    var sprytextfield5 = new Spry.Widget.ValidationTextField("sprytextfield5", "none", {minChars:2, maxChars:4});
    var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2", {validateOn:["blur", "change"]});
          </script></h1>
    Here is the FormToMail.php:
    <?php
    $my_email = "[email protected]";
    $continue = "page_ContactThanks.html";
    $errors = array();
    // Remove $_COOKIE elements from $_REQUEST.
    if(count($_COOKIE)){foreach(array_keys($_COOKIE) as $value){unset($_REQUEST[$value]);}}
    // Check all fields for an email header.
    function recursive_array_check_header($element_value)
    global $set;
    if(!is_array($element_value)){if(preg_match("/(%0A|%0D|\n+|\r+)(content-type:|to:|cc:|bcc: )/i",$element_value)){$set = 1;}}
    else
    foreach($element_value as $value){if($set){break;} recursive_array_check_header($value);}
    recursive_array_check_header($_REQUEST);
    if($set){$errors[] = "You cannot send an email header";}
    unset($set);
    // Validate email field.
    if(isset($_REQUEST['Email']) && !empty($_REQUEST['Email']))
    if(preg_match("/(%0A|%0D|\n+|\r+|:)/i",$_REQUEST['Email'])){$errors[] = "Email address may not contain a new line or a colon";}
    $_REQUEST['Email'] = trim($_REQUEST['Email']);
    if(substr_count($_REQUEST['Email'],"@") != 1 || stristr($_REQUEST['Email']," ")){$errors[] = "Email address is invalid";}else{$exploded_email = explode("@",$_REQUEST['Email']);if(empty($exploded_email[0]) || strlen($exploded_email[0]) > 64 || empty($exploded_email[1])){$errors[] = "Email address is invalid";}else{if(substr_count($exploded_email[1],".") == 0){$errors[] = "Email address is invalid";}else{$exploded_domain = explode(".",$exploded_email[1]);if(in_array("",$exploded_domain)){$errors[] = "Email address is invalid";}else{foreach($exploded_domain as $value){if(strlen($value) > 63 || !preg_match('/^[a-z0-9-]+$/i',$value)){$errors[] = "Email address is invalid"; break;}}}}}}
    // Check referrer is from same site.
    if(!(isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) && stristr($_SERVER['HTTP_REFERER'],$_SERVER['HTTP_HOST']))){$errors[] = "You must enable referrer logging to use the form";}
    // Check for a blank form.
    function recursive_array_check_blank($element_value)
    global $set;
    if(!is_array($element_value)){if(!empty($element_value)){$set = 1;}}
    else
    foreach($element_value as $value){if($set){break;} recursive_array_check_blank($value);}
    recursive_array_check_blank($_REQUEST['message']);
    if(!$set){$errors[] = "You cannot send a blank form";}
    unset($set);
    // Display any errors and exit if errors exist.
    if(count($errors)){foreach($errors as $value){print "$value<br>";} exit;}
    if(!defined("PHP_EOL")){define("PHP_EOL", strtoupper(substr(PHP_OS,0,3) == "WIN") ? "\r\n" : "\n");}
    // Build message.
    function build_message($request_input){if(!isset($message_output)){$message_output ="";}if(!is_array($request_input)){$message_output = $request_input;}else{foreach($request_input as $key => $value){if(!empty($value)){if(!is_numeric($key)){$message_output .= str_replace("_"," ",ucfirst($key)).": ".build_message($value).PHP_EOL.PHP_EOL;}else{$message_output .= build_message($value).", ";}}}}return rtrim($message_output,", ");}
    $message = build_message($_REQUEST);
    $message = $message . PHP_EOL.PHP_EOL."-- ".PHP_EOL."Thank you. Your message has been sent";
    $message = stripslashes($message);
    $subject = "ASA Services Message";
    $headers = "From: " . $_REQUEST['Email'];
    ?>
    </body>
    </html>

    I went through and changed the spry validation fields to just text fields and now everything seems to be working but I do not recieve the email. It gets the error message "invalid email address. Please return to the previous page. Any idea why this is happening? My email address is entered correctly.
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <META HTTP-EQUIV="refresh" content="0;URL=thankyou.html">
    <title>Email Form</title>
    </head>
    <body>
    <?php
      $Name=addslashes($_POST['Name']);
      $Email=addslashes($_POST['Email']);
      $PhoneNumber=addslashes($_POST['Phone']);
      $Birthday=addslashes($_POST['Birthday']);
      $DDD=addslashes($_POST['DD']);
      $YYYY=addslashes($_POST['YYYY']);
      $Gender=addslashes($_POST['Gender']);
      $CoverageAmount=addslashes($_POST['CoverageAmount']);
      $CoverageLength=addslashes($_POST['CoverageLength']);
      $TobaccoUse=addslashes($_POST['TobaccoUse']);
      $radioGroup1=addslashes($_POST['RadioGroup1']);
      $radioGroup2=addslashes($_POST['RadioGroup2']);
      $radioGroup3=addslashes($_POST['RadioGroup3']);
      $toemail = "[email protected]";
      $subject = "From PrivateInsuranceBrokers.com";
      $headers = "MIME-Version: 1.0\n"
                ."From: \"".$name."\" <".$email.">\n"
                ."Content-type: text/html; charset=iso-8859-1\n";
      $body =  "First_Name: ".$Name."<br>\n"
              ."Email: ".$Email."<br>\n"
      ."PhoneNumber: ".$Phone."<br>\n"
      ."Birthday: ".$Birthday."<br>\n"
              ."DD: ".$DD."<br>\n"
      ."YYYY: ".$YYYY."<br>\n"
      ."Gender: ".$Gender."<br>\n"
      ."CoverageAmount: ".$CoverageAmount."<br>\n"
      ."CoverageLength: ".$CoverageLength."<br>\n"
      ."TobaccoUse: ".$TobaccoUse."<br>\n"
        ."radioGroup1: ".$RadioGroup1."<br>\n"
            ."radioGroup2: ".$RadioGroup2."<br>\n"
      ."radioGroup3: ".$RadioGroup3."<br>\n";
      if (!ereg("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $email))
        echo "That is not a valid email address.  Please return to the"
               ." previous page and try again.";
        exit;
        mail($toemail, $subject, $body, $headers);
        echo "Thank you for submitting your Life Insurance Request. Our agency will contact you shortly";
    ?>
    </body>
    </html>
    Form Code:
        <h1 align="center">Request A Life Insurance Quote    </h1>
        <div align="center">
          <table border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="590" height="984" valign="top"><form id="FrmLifeQuote" name="FrmLifeQuote" method="post" action="formmail.php">
                  <div align="left"></div>
                  <fieldset class="text">
                    <p align="left">
                      <label for="Name">Name:</label>
                      <input type="text" name="Name" id="Name" tabindex="10" />
                    </p>
                  <p align="left">
                    <label for="Email2">Email:</label>
                    <input type="text" name="Email" id="Email2" tabindex="20" />
                  </p>
                  <p align="left">
                    <label for="Phone">Phone Number:</label>
                    <input type="text" name="Phone" id="Phone" tabindex="30" />
                  </p>
                  <p align="left"> </p>
                  </fieldset>
                <fieldset>
                <p align="left">
                  <legend class="text"></legend>          
                  <p align="left">
                    <label for="Birthday">Birthday:</label>
                    <select name="Birthday" id="Birthday" tabindex="40">
                      <option value="MM">MM</option>
                      <option value="01">01</option>
                      <option value="02">02</option>
                      <option value="03">03</option>
                      <option value="04">04</option>
                      <option value="05">05</option>
                      <option value="06">06</option>
                      <option value="07">07</option>
                      <option value="08">08</option>
                      <option value="09">09</option>
                      <option value="10">10</option>
                      <option value="11">11</option>
                      <option value="12">12</option>
    </select>
                    <select name="DD" id="DD" tabindex="50">
                      <option value="DD">DD</option>
                      <option value="01">01</option>
                      <option value="02">02</option>
                      <option value="03">03</option>
                      <option value="04">04</option>
                      <option value="05">05</option>
                      <option value="06">06</option>
                      <option value="07">07</option>
                      <option value="08">08</option>
                      <option value="09">09</option>
                      <option value="10">10</option>
                      <option value="11">11</option>
                      <option value="12">12</option>
                      <option value="13">13</option>
                      <option value="14">14</option>
                      <option value="15">15</option>
                      <option value="16">16</option>
                      <option value="17">17</option>
                      <option value="18">18</option>
                      <option value="19">19</option>
                      <option value="20">20</option>
                      <option value="21">21</option>
                      <option value="22">22</option>
                      <option value="23">23</option>
                      <option value="24">24</option>
                      <option value="25">25</option>
                      <option value="26">26</option>
                      <option value="27">27</option>
                      <option value="28">28</option>
                      <option value="29">29</option>
                      <option value="30">30</option>
                      <option value="31">31</option>
                    </select><label for="YYYY"></label>
                    <input name="YYYY" type="text" id="YYYY" tabindex="60" value="YYYY" />
                  </p>
                  <p align="left">
                    <label for="Gender">Gender:</label>
                    <select name="Gender" id="Gender" tabindex="70">
                      <option value="Select">Select</option>
                      <option value="Female">Female</option>
                      <option value="Male">Male</option>
                    </select>
                  </p>
                  <p align="left">
                    <label for="CoverageAmount">Coverage Amount:</label>
                  <select name="CoverageAmount" id="CoverageAmount" tabindex="80">
                    <option value="Select">Select</option>
                    <option value="$250,000">$250,000</option>
                    <option value="$500,000">$500,000</option>
                    <option value="$750,000">$750,000</option>
                    <option value="$1,000,000">$1,000,000</option>
                    <option value="$1,250,000">$1,250,000</option>
                    <option value="$1,500,000">$1,500,000</option>
                    <option value="$1,750,000">$1,750,000</option>
                    <option value="$2,000,000">$2,000,000</option>
                    <option value="$2,500,000">$2,500,000</option>
                    <option value="$3,000,000">$3,000,000</option>
                    <option value="$3,500,000">$3,500,000</option>
                    <option value="$4,000,000">$4,000,000</option>
                    <option value="$5,000,000">$5,000,000</option>
                  </select>
              </p>
                <p align="left">
                  <label for="CoverageLength">Coverage Length:</label>
                  <select name="CoverageLength" id="CoverageLength"tabindex="81">
                    <option value="Select" selected="selected">Select</option>
                    <option value="10 Year">10 Year</option>
                    <option value="15 Year">15 Year</option>
                    <option value="20 Year">20 Year</option>
                    <option value="25 Year">25 Year</option>
                    <option value="30 Year">30 Year</option>
                    <option value="UL">UL</option>
                    </select>
                </p>
                <p align="left" class="text">
                  <label for="TobaccoUse">Tobacco Use:</label>
                  <select name="TobaccoUse" id="TobaccoUse" tabindex="90">
                    <option value="Select" selected="selected">Select</option>
                    <option value="None">None</option>
                    <option value="Cigarette">Cigarette</option>
                    <option value="Cigar">Cigar</option>
                    <option value="Pipe">Pipe</option>
                    <option value="Chewing Tobacco">Chewing Tobacco</option>
                    <option value="Nicotine Patch">Nicotine Patch</option>
                    <option value="Gum">Gum</option>
                    </select>
                </p>
                <p align="left" class="text">Have you ever been treated for Cancer, Heart Disease, Stroke, Diabetes, High Blood Pressure, Alcohol or Drug Abuse, Depression, Asthma, or any other similar conditions?                    <br />         
                  <p align="left">
                    <label>
                      <input type="radio" name="RadioGroup1" value="Yes" id="RadioGroup1_0" />
                    Yes</label>
                    <br />
                    <label>
                      <input type="radio" name="RadioGroup1" value="No" id="RadioGroup1_1" />
                    No</label>
                    <br />
                  </p>
                <p align="left" class="text">Have you had more than 2 citations for moving violations in the past three years?          
                  <p align="left">
                    <label>
                      <input type="radio" name="RadioGroup2" value="Yes" id="RadioGroup2_0" />
                    Yes</label>
                    <br />
                    <label>
                      <input type="radio" name="RadioGroup2" value="No" id="RadioGroup2_1" />
                    No</label>
                    <br />
                  </p>
                <p align="left" class="text">Do you do any hazardous activities?
                  <p align="left">
                    <label>
                      <input type="radio" name="RadioGroup3" value="Yes" id="RadioGroup3_0" />
                    Yes</label>
                    <br />
                    <label>
                      <input type="radio" name="RadioGroup3" value="No" id="RadioGroup3_1" />
                    No</label>
                    <br />
                  </p>
                <p align="left" class="text">
                  <input type="submit" name="Submit" id="Submit" value="Request A Life Insurance Quote" tabindex="130" />
                <p align="left" class="text">             
                <p align="left" class="text">           
              </form></td>
            </tr>
          </table>
        </div>

  • VS.PHP vs PHP TOOLS for Visual Studio : which is the best ?

    Hi,
    I love Visual Studio. I use it since 2006 for c#, asp, WinForm project, etc. I have a question about PHP / Simple Web dev : 
    Which is the extention between VS.PHP and PHP TOOLS ?
    What i need :
    - Intellisence (auto completion all PHP core class and functions and major extention, project lib class and functions)
    - Powerfull debug, with break points etc...
    -Web server integartion (apache, nginx, mysql) 
    - Live edit over FTP
    - Publish over FTP the file projet
    - MySQL Integration (design tools, etc ?)
    [- Integration of some platform like Drupal or Wordpress (intellisence and debut)
    - Integartion with other HTML/Javascript framework (jquery, angular etc.) ]
    - CONTROL + K + D indentation for all documents
    Thanks for your opinion.

    Hi nicpulse,
    Thank you for posting in MSDN forum.
    Since this forum is to discuss: Visual Studio WPF/SL Designer, Visual Studio Guidance Automation Toolkit, Developer Documentation
    and Help System, and Visual Studio Editor.
    >>VS.PHP vs PHP TOOLS for Visual Studio : which is the best ?
    Based on your issue, since the PHP Tools and VS.PHP are involved to the Extensions tool,
    this extension tool is out of support range of this forum.
    In my option, I think that there have no specified answer about which is the best in the
    VS.PHP vs PHP TOOLS for Visual Studio.
    It is just depend on which is appropriate for your requirement, so I suggest you can see the feature about the VS.PHP and
    PHP Tools. And then choose which extension tool is appropriate your requirement.
    https://visualstudiogallery.msdn.microsoft.com/F5CFBE65-D843-4C96-8F24-2C169676504Chttps://visualstudiogallery.msdn.microsoft.com/6eb51f05-ef01-4513-ac83-4c5f50c95fb5
    In order to resolve your issue better, I suggest you post this issue to
    PHP Tools
    for Visual Studio or
    VS.Php for Visual Studio, click “Q AND A”, you will get better support there.
    Thanks for your understanding.
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Remotely call a PHP function?

    My alliance in a game uses a tool to keep track of information. I am trying to make a program that allows me to simply copy information I want to submit to the system's clipboard and then push it to the "submit form" of the alliance's website.
    At any rate, I have the clipboard part working. The part that isn't working is pushing the update to the server. The page I want is called:
    spioparser.inc.php
    The class declared in that PHP file is "Probeparser"
    and the specific function in that file I want to call is "parseEntry($string,$flush=true)"
    Is it even possible to have my java program open a connection to the server and send information to this function (this function will automatically insert it into the database.)?
    The code I am using to try and connect to the server is this:
    URL Gala = new URL("http://" +
                        "<username>:<password>@" +
                        "mtuogame.lhosting.info/GalaxyTool/secret/spioparser.inc.php");
                   HttpURLConnection Connection =
                        (HttpURLConnection) Gala.openConnection();
                   Connection.setDoInput(true);
                   Connection.setDoOutput(true);
                   Connection.setRequestProperty( "Content-type",
                        "application/x-www-form-urlencoded" );
                   Connection.setRequestProperty( "Content-length",
                        Integer.toString(Input.length()));
                   DataInputStream tmp = new DataInputStream(Connection.getInputStream());
                   readInput(tmp); //reads all input until EOF
                   PrintWriter out = new PrintWriter(Connection.getOutputStream());
                   out.print(Input); //sends the report to server?Thanks.
    -Kingdud

    If you have things set up so that some HTTP request will call that function, then you can certainly call that HTTP request from Java code. As you already know.
    But generally you can't just reach out over the network and run arbitrary executable code on somebody else's computer. (Think for a minute what security implications that would have.) Java or not, the answer is the same.

  • ADDT and PHP 5.3.x project

    Hello all, as 'abandon' user of ADDT... i hope we can together make ADDT compatible for future release of PHP.
    Currently PHP 5.3 our main 'enemy'.
    The 'patch' that i summarized far from other thread:
    1. function split() found in:
    - includes\common\lib\file\KT_File.class.php
    - includes\common\lib\file_upload\KT_FileUpload.class.php
    - includes\common\lib\folder\KT_Folder.class.php
    - includes\common\lib\image\KT_Image.class.php
    occurences found: one instance per file
    possible fix: try replacing with preg_split()
    2. function mysql_escape_string() found in:
    - includes\common\lib\db\KT_FakeRecordset.class.php
    occurences found: three instances
    possible fix: try replacing with mysql_real_escape_string() but better to use function_exists so it still keep compatible with previous php version, for example :
    if(function_exists(”mysql_real_escape_string”)){
    $insert_values .= “‘” . mysql_real_escape_string($value) . “‘, “;
    }else{
    $insert_values .= “‘” . mysql_escape_string($value) . “‘, “;
    Other than that a handful of other ADDT files make an ini_get() – call to some deprecated PHP.INI functions such as safe_mode — but I´m not sure if this would trigger errors, because ADDT just tries to retrieve the related INI values and doesn´t atempt to change them.
    3. find "= &new"  and replace with "= new";
    4.  Look inside includes/tng/tNG_insert.class.php, tNG_update.class.php, tNG_delete.class.php and tNG_custom.class.php and replace
    parent::tNG_fields($connection); with parent::tNG($connection);
    I've no idea about solution no.4, since parent:: usually(as far as i know) use for direct access a method on parent's class... but the solution works for me
    As We're talking about live project here (i'm serious about this)  without legitimate technical support.  I have an idea if we can make a group and hire an expert programmer to audit ADDT's includes folder so it will compatible with PHP 5.3.x.. But, does it mean we break our license policy with adobe ?
    ========================
    Hope this thread will alive and so does our ADDT's project
    ========================

    I've been running a custom CMS for the past 2 years, which was build on ADDT. I finally got the courage to setup a 5.3 test server just to see how it stands. Some of the ADDT features used on the CMS are as follows:
    Includes
    Dymanic Lists and Forms
    Image Uploads
    List Sorting
    Widgets
    Send Email
    much, much more
    When I first ran the sites front end, everything was perfect. All I did was update a few of the files as recommended on these forums. That was about 15 minutes work, and voila - the display of the sites contents was great.
    However - when I dove into the admin area, that is where the problems started. Most of the problems were simply errors, that pinpointed where the problem was, and for the most part - the problem was already outlined on these forums, but the include file was not mentioned (eg: don't just update "tNG_insert.class.php", you also need to update "tNG_multipleInsert.class.php" and several others.
    NOW I AM STUCK! This is on the lists and forms. Both of these items display properly, but when I try to update a record, an error is thrown that I cannot find a fix for. This same error is appearing on Joomla and Drupal forums all over the internet, and the only solution I ever see is "wait for the 5.3 update for the program". OF COURSE, THAT IS NOT COMING FOR ADDT!
    Since lists and forms is the most used feature (for me anyway) of ADDT, it is rendering ADDT completely useless on PHP 5.3.
    THE ERROR:
    "PHP Warning: Parameter 2 to Trigger_Default_FormValidation() expected to be a reference, value given in D:\sites\pra2.ca\public_html\includes\tng\tNG.class.php on line 228"
    I know this has to do with the "pass by reference" deprecation, but I cannot figure out how to fix this problem. I am able to supress the warning with the @ symbol, and therefore I can continue testing. But that is just hiding the problem, not fixing it.
    Any suggestions would be appeciated

  • MPD hangs when changing tracks or seeking

    MPD is VERY touchy when I change the current playing track, or seek.
    I've been using ncmpcpp, but I witness the same behavior with other clients too.
    Since I've seen other people mention the same stability issues, I was wondering if anyone came up with a solution for this ?
    I was hoping to use mpd to build my music db, but I 'skim' through a lot of music, so it's not usable to me right now...
    Will appreciate any help.
    Cheers
    Last edited by disturb (2010-01-02 10:54:20)

    disturb wrote:
    MPD is VERY touchy when I change the current playing track, or seek.
    I've been using ncmpcpp, but I witness the same behavior with other clients too.
    Since I've seen other people mention the same stability issues, I was wondering if anyone came up with a solution for this ?
    I was hoping to use mpd to build my music db, but I 'skim' through a lot of music, so it's not usable to me right now...
    Will appreciate any help.
    Cheers
    http://wiki.archlinux.org/index.php/MPD
    Try that link out and try setting it up via user in the alternate setup.  I had issues it running as deamon... This way it will run as a local user and just add it to a start script when you start your .xinitrc or autostart.sh...
    Last edited by JuseBox (2010-01-02 11:50:17)

  • How can I get mpd + sonata working

    Hello, I have followed the wiki page for MPD: http://wiki.archlinux.org/index.php/Mpd , but I can't get it working, always sonata is telling to me that MPD connection is time out.
    from /etc/mpd.conf I have modified only that:
    music_directory                  "/home/davigetto/Musica"
    I make successfully /etc/rc.d/mpd create-db:
    [root@samantha davigetto]# /etc/rc.d/mpd create-db
    :: Creating mpd's database ... [BUSY] :: Output written to /var/log/mpd/mpd.db-creation [DONE]
    and when trying to start mpd daemon, always it fails:
    [root@samantha davigetto]# /etc/rc.d/mpd restart
    :: Stopping Music Player Daemon [FAIL]
    :: Starting Music Player Daemon [FAIL]
    [root@samantha davigetto]#
    what steps must I follow to get MPD working correctly, and sonata too?
    Greetings

    Hi, u need to have /etc/mpd.conf configured properly for mpd to work, try this for example:
    music_directory "~/home/davigetto/Musica"
    playlist_directory "~/.mpd/playlists"
    db_file "~/.mpd/mpd.db"
    log_file "~/.mpd/mpd.log"
    error_file "~/.mpd/mpd.error"
    pid_file "~/.mpd/mpd.pid"
    state_file "~/.mpd/mpdstate"
    user "davigetto"
    bind_to_address "127.0.0.1"
    port "6600"
    audio_output {
    type "alsa"
    name "My ALSA Device"
    mixer_type "software"
    Reboot and then type in terminal 'mpd --create-db'
    After the database is created start sonata and you should be able to play your music.

  • PHP form submission Problem

    Dear all,
    PHP enquiry form submission some error is comes
    "Parse error: syntax error, unexpected T_STRING in /home/newtocli/public_html/en45/send_form_email.php on line 11"
    Please help me
    WEBLINK
    PHP goes like this
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>PHP Form</title>
    </head>
    <body><?php
    if(isset($_POST['email'])) {
        // EDIT THE 2 LINES BELOW AS REQUIRED
        $email_to = "[email protected]";
        $email_subject = "Your email subject line";
        function died($error) {
            // your error code can go here
            echo "We are very sorry, but there were error(s) found with the form you submitted. ";
            echo "These errors appear below.<br /><br />";
            echo $error."<br /><br />";
            echo "Please go back and fix these errors.<br /><br />";
            die();
        // validation expected data exists
        if(!isset($_POST['first_name']) ||
            !isset($_POST['email']) ||
            !isset($_POST['telephone']) ||
                        !isset($_POST['company_name']) ||
            !isset($_POST['comments'])) {
            died('We are sorry, but there appears to be a problem with the form you submitted.');      
        $first_name = $_POST['first_name']; // required
        $email_from = $_POST['email']; // required
        $telephone = $_POST['telephone']; // not required
              $last_name = $_POST['company_name']; // required
        $comments = $_POST['comments']; // required
        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
      if(!preg_match($email_exp,$email_from)) {
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
        $string_exp = "/^[A-Za-z .'-]+$/";
      if(!preg_match($string_exp,$first_name)) {
        $error_message .= 'The First Name you entered does not appear to be valid.<br />';
      if(!preg_match($string_exp,$company_name)) {
        $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
      if(strlen($comments) < 2) {
        $error_message .= 'The Comments you entered do not appear to be valid.<br />';
      if(strlen($error_message) > 0) {
        died($error_message);
        $email_message = "Form details below.\n\n";
        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        $email_message .= "First Name: ".clean_string($first_name)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Telephone: ".clean_string($telephone)."\n";
              $email_message .= "Company Name: ".clean_string($company_name)."\n";
        $email_message .= "Comments: ".clean_string($comments)."\n";
    /* Redirect visitor to the thank you page */
    header('Location:gt.html');
    exit();
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers); 
    ?>
    <!-- include your own success html here -->
    Thank you for contacting us. We will be in touch with you very soon.
    <?php
    ?>
    </body>
    </html>

    some error now
    Parse error: syntax error, unexpected T_STRING in /home/newtocli/public_html/send_form_email.php on line 5
    My form like this
    <form name="contactform" method="post" action="send_form_email.php">
                                                                                                                                                <div class="field text">
                                                            <input  type="text" name="first_name" maxlength="50" size="30" value="Name*:">
                                                            </div>
                                                                                                                                                <div class="field text">
                                                            <input  type="text" name="email" maxlength="80" size="30" value="E-mail*:">
                                                           </div>
                                                                          <div class="clear"><!-- --></div>
                                                                                                                                                <div class="field text">
                                                            <input  type="text" name="telephone" maxlength="30" size="30" value="Phone.:">
                                                            </div>
                                                                                                                                                <div class="field text">
                                                            <input  type="text" name="company_name" maxlength="50" size="30" value="Company:">
                                                            </div>
                                                                          <div class="clear"><!-- --></div>
                                                                          <div class="field textarea"><div>
                                                                            <textarea  name="comments"></textarea>
                                </div></div>
                                                                          <div class="submit">
                                                                                    <p>* - Required fields</p>
                                                                                    <input type="submit" value="Send" />
                                                                          </div>
                                                                </form>

  • Help with html / php contact form

    Hi guys I was hoping to get some help with a contact form on my website, to be honest I havent a clue about php but kind of okay with html thats why the php code is just a copy and paste from some website, just trying to marry it up with the html but getting errors.
    Hopfully one of you can see the problem.
    Error on Submitting:
    Notice: Undefined variable: name in \\nas44ent\Domains\g\gethinhayman.co.uk\user\htdocs\send_form_email.php on line 69
    Notice: Undefined variable: message in \\nas44ent\Domains\g\gethinhayman.co.uk\user\htdocs\send_form_email.php on line 75
    We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.
    The Name you entered does not appear to be valid.
    The Comments you entered do not appear to be valid.
    HTML Code:
    <section id="contact" class="four">
                                                                <div class="container">
                                                                          <header>
                                                                                    <h2>Contact</h2>
                                                                          </header>
                                                                          <form method="post" action="send_form_email.php">
                                                                                    <div class="row half">
                                                                                              <div class="6u"><input type="text" class="text" name="name" placeholder="Name" /></div>
                                                                                              <div class="6u"><input type="text" class="text" name="email" placeholder="Email" /></div>
                                                                                    </div>
                                                                                    <div class="row half">
                                                                                              <div class="12u">
                                                                                                        <textarea name="message" placeholder="Message"></textarea>
                                                                                              </div>
                                                                                    </div>
                                                                                    <div class="row">
                                                                                              <div class="12u">
                                                                                                        <a href="http://www.mywebsite.co.uk/email_form.php" class="button submit">Send Message</a>
                                                                                              </div>
                                                                                    </div>
                                                                          </form>
                                                                </div>
                                                      </section>
    php Code:
    <?php
    if(isset($_POST['email'])) {
        $email_to = "my email address";
        $email_subject = "Mail from Site";
        function died($error) {
            // your error code can go here
            echo "We are very sorry, but there were error(s) found with the form you submitted. ";
            echo "These errors appear below.<br /><br />";
            echo $error."<br /><br />";
            echo "Please go back and fix these errors.<br /><br />";
            die();
        // validation expected data exists
        if(!isset($_POST['name']) ||
            !isset($_POST['email']) ||
            !isset($_POST['message'])) {
            died('We are sorry, but there appears to be a problem with the form you submitted.');      
        $first_name = $_POST['name']; // required
        $email_from = $_POST['email']; // required
        $comments = $_POST['message']; // required
        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
      if(!preg_match($email_exp,$email_from)) {
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
        $string_exp = "/^[A-Za-z .'-]+$/";
      if(!preg_match($string_exp,$name)) {
        $error_message .= 'The Name you entered does not appear to be valid.<br />';
      if(strlen($message) < 1) {
        $error_message .= 'The Comments you entered do not appear to be valid.<br />';
      if(strlen($error_message) > 0) {
        died($error_message);
        $email_message = "Form details below.\n\n";
        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        $email_message .= "Name: ".clean_string($name)."\n";;
        $email_message .= "Email: ".clean_string($email)."\n";
        $email_message .= "Message: ".clean_string($message)."\n";
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers); 
    ?>
    <?php
    ?>

    PHP CODE:  SaveAs send_form_email.php
    <?php
    if(isset($_POST['email'])) {
        // EDIT THE 2 LINES BELOW AS REQUIRED
        $email_to = "[email protected]";
        $email_subject = "Your email subject line";
        function died($error) {
            // your error code can go here
            echo "We are very sorry, but there were error(s) found with the form you submitted. ";
            echo "These errors appear below.<br /><br />";
            echo $error."<br /><br />";
            echo "Please go back and fix these errors.<br /><br />";
            die();
        // validation expected data exists
        if(!isset($_POST['name']) ||
            !isset($_POST['email']) ||
            !isset($_POST['message'])) {
            died('We are sorry, but there appears to be a problem with the form you submitted.');     
        $name = $_POST['name']; // required
        $email_from = $_POST['email']; // required
        $comments = $_POST['message']; // required
        $error_message = "";
        $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
      if(!preg_match($email_exp,$email_from)) {
        $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
        $string_exp = "/^[A-Za-z .'-]+$/";
      if(!preg_match($string_exp,$name)) {
        $error_message .= 'The Name you entered does not appear to be valid.<br />';
      if(strlen($message) < 2) {
        $error_message .= 'The message you entered does not appear to be valid.<br />';
      if(strlen($error_message) > 0) {
        died($error_message);
        $email_message = "Form details below.\n\n";
        function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
        $email_message .= "Name: ".clean_string($name)."\n";
        $email_message .= "Email: ".clean_string($email_from)."\n";
        $email_message .= "Message: ".clean_string($message)."\n";
    // create email headers
    $headers = 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    ?>
    <!-- include your own success html here -->
    Thank you for contacting us. We will be in touch with you very soon.
    <?php
    ?>
    HTML Code -- save as html page.
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Contact Form</title>
    </head>
    <body>
    <section id="contact" class="four">
    <div class="container">
    <header>
    <h2>Contact</h2>
    </header>
    <form method="post" action="send_form_email.php">
    <div class="row half"> <div class="6u">
    <input type="text" class="text" name="name" placeholder="Name" />
    </div>
    <div class="6u">
    <input type="text" class="text" name="email" placeholder="Email" />
    </div>
    </div>
    <div class="row half"> <div class="12u">
    <textarea name="message" placeholder="Message"></textarea>
    </div>
    </div>
    <div class="row">
    <div class="12u">
    <input type="submit" name="submit" value="Send">
    </div>
    </div>
    </form>
    </div>
    </section>
    </body>
    </html>
    Upload both to your Apache server to test.
    EDIT:  changed typo on Submit button -- valuse to value.
    Nancy O.

  • ANN: PHP Object-Oriented Solutions

    This is not directly related to Dreamweaver, but I know a lot
    of people
    here use PHP. My latest book, "PHP Object-Oriented Solutions"
    has just
    been published and is already in stock at Amazon.com and
    www.compman.co.uk. It's aimed at intermediate PHP developers
    who want to
    create reusable code through PHP 5 classes. It explains the
    basic
    principles of Object-Oriented Programming (OOP), and contains
    practical
    examples, such as a server-side validation class, generating
    XML and RSS
    feeds, and simplifying date handling. It also explains
    several powerful
    features of PHP 5, such as SimpleXML, XMLWriter, and the
    Standard PHP
    Library (SPL).
    The book concentrates exclusively on PHP 5. The code will not
    work on PHP 4.
    David Powers, Adobe Community Expert
    Author, "The Essential Guide to Dreamweaver CS3" (friends of
    ED)
    Author, "PHP Solutions" (friends of ED)
    http://foundationphp.com/

    http://www.amazon.com/dp/1430210117?tag=japaninterfac-20&camp=14573&creative=327641&linkCo de=as1&creativeASIN=1430210117&adid=1HERPDYNB05EX6CJB7D2&
    http://tinyurl.com/63bkgu
    Ken Ford
    Adobe Community Expert Dreamweaver/ColdFusion
    Fordwebs, LLC
    http://www.fordwebs.com
    "Joe Makowiec" <[email protected]> wrote in
    message
    news:[email protected]..
    > On 19 Aug 2008 in macromedia.dreamweaver.appdev, David
    Powers wrote:
    >
    >> Michael White wrote:
    >>> From where do you recommend I buy it? (NY, USA)
    >>
    >> The place that would bring the greatest benefit to
    me is through the
    >> Amazon.com link on my site (see link in my sig).
    Amazon in the USA
    >> is offering it at a 34% discount. However, I'm
    delighted if anyone
    >> buys it anywhere.
    >
    > I didn't see a link to US Amazon, only Canada and UK?
    >
    > --
    > Joe Makowiec
    >
    http://makowiec.net/
    > Email:
    http://makowiec.net/contact.php

Maybe you are looking for

  • Can I activate the Cloud software on more than one computer? [was:Gerry]

    I purchased a single user PS CC license last year. During the interim the nature of my work has neccesitated that I have to work at two sepearte offices (one at home and one at my formal offices). Is it possible to "switch" the license to the differe

  • Aperture with iPhoto questions

    Hi gang, The new integration of iPhoto and Aperture 1.5 sounds very appealing. I have a couple of questions regarding functionality. Let's assume that I have Aperture set to use my iPhoto library in referenced file mode. 1) Will Aperture keep the two

  • Error when trying to process a dimension

    When I try to add some members in the dimension, it says Student_account(name of dimension)'s member OEM has a invalid hierarchy parent "confg". Please advise. thanks.

  • Connecting TC as a Wireless NDAS or Wireless NAS

    A week ago, I have purchased the TC in order to connect it as a Wireless NDAS (or NAS) within my home network. I have Windows 7 Ultimate, so I used the AirPort Utility V 7.6.1 to configure it. I am an IT Admin (Windows and Mac), and I will try to sum

  • BAD: Outlook Calendar items are removed as they occur!

    I canceled my ME.COM account because it didn't work at all. The syncing affected my calendar and it looks like it tweaked something in iTunes. When I sync - it looks like iTunes decides to remove events from my calendar in Outlook 2007. This is *TOTA