Question

I have a form...

<form action="response.php" method="get" name="titles">
<p><input id="titles" onclick="this.select()" type="text" name="titles" value="Live Now! DJ Name - Show Name" /> <input type="submit" value="Submit" /></p>
</form>

Delivering a variable $titles to response.html. However it's not working correctly.

The format of my response.php output should be...

http://adminusername:adminpassword@mysite.com:8000/admin/metadata?mount=/mountname&mode=updinfo&song=$myvariableforminputhere

Here is response.html The form seems to work, but I have something wrong with including my variable. I'm a bit of a hack sorry, and have borrowed bits of other peoples code:/

<html>
<head>
<title>PHP Form Variables Example</title>
</head>
<body>

<?php
{
//simply copy and paste this code block for each server you need to add
$serv["host"][] = "mysite.com"; //ip or hostname the server is running on. Don't include http://
$serv["port"][] = "8000"; //port the server is running on
$serv["mount"][] = "/mymount"; //this format: /mount
$serv["user"][] = "user"; //icecast server username
$serv["passwd"][] = "pass"; //icecast server password
echo $_GET["titles"];

    {
        $mysession = curl_init();
        curl_setopt($mysession, CURLOPT_URL, "http://".$serv["host"][$count].":".$serv["port"][$count]."/admin/metadata?mount=".$serv["mount"][$count]."&mode=updinfo&song=test".$titles);
        curl_setopt($mysession, CURLOPT_HEADER, false);
        curl_setopt($mysession, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($mysession, CURLOPT_POST, false);
        curl_setopt($mysession, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($mysession, CURLOPT_USERPWD, $serv["user"][$count].":".$serv["passwd"][$count]);
        curl_setopt($mysession, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($mysession, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
        curl_setopt($mysession, CURLOPT_CONNECTTIMEOUT, 2);
        curl_exec($mysession);
        curl_close($mysession);
    }

    echo "song updated";
}
?>

<p><a href="javascript:history.go(-1)">Back</a></p>

</body>
</html> 

Edit:

Thanks to User: byf-ferdy the below response.php now works with my form code above. Thanks also to Audioprobe at http://forum.loudcity.net/viewtopic.php?id=4160 for the original code!

<html>
<head>
<script>
//Set up java for back button
function goBack()
  {
  window.history.back()
  }
</script>
</head>
<body>

<?php

//simply copy and paste this code block for each server you need to add
$serv["host"][] = "mysite.com"; //ip or hostname the server is running on. Don't include http://
$serv["port"][] = "8000"; //port the server is running on
$serv["mount"][] = "/mymount"; //this format: /mount
$serv["user"][] = "user"; //icecast server username
$serv["passwd"][] = "pass"; //icecast server password

$encoded = urlencode($_GET['titles']); //Make sure '+' and spaces are sent correctly by encoding all +'s to be %2B

        $mysession = curl_init();
        curl_setopt($mysession, CURLOPT_URL, "http://".$serv["host"].":".$serv["port"]."/admin/metadata?mount=".$serv["mount"]."&mode=updinfo&song=".$encoded);
        curl_setopt($mysession, CURLOPT_HEADER, false);
        curl_setopt($mysession, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($mysession, CURLOPT_POST, false);
        curl_setopt($mysession, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($mysession, CURLOPT_USERPWD, $serv["user"].":".$serv["passwd"]);
        curl_setopt($mysession, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($mysession, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
        curl_setopt($mysession, CURLOPT_CONNECTTIMEOUT, 2);
        curl_exec($mysession);
        curl_close($mysession);

    echo "Titles updated: ";
    echo $_GET["titles"];

?>
<!--Implement back button-->
<p><input type="button" value="Back" onclick="goBack()"></p>
</form>

</body>
</html> 
Was it helpful?

Solution

As I already wrote in my comments you should remove the curly brackets since they are obsolete in your code. Also remove in all the lines

$serv["host"][] = "budgiecollective.dyndns.org";

the [] so the line just looks like this:

$serv["host"] = "budgiecollective.dyndns.org"; 

Afterwards remove any occurance of [$count] in your code since the variable is not used anymore. Last but not least change the $titles to $_GET['titles'] in this line:

curl_setopt($mysession, CURLOPT_URL, "http://".$serv["host"][$count].":".$serv["port"][$count]."/admin/metadata?mount=".$serv["mount"][$count]."&mode=updinfo&song=test".$titles);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top