2013-06-18 48 views
1

我有一個表格...PHP,嫋嫋獲取變量和響應

<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> 

交付一個變量$職稱response.html。但它不能正常工作。

我response.php輸出應的格式...

http://adminusername:[email protected]:8000/admin/metadata?mount=/mountname&mode=updinfo&song=$myvariableforminputhere 

這裏是response.html形式似乎工作,但我有什麼毛病,包括我的變量。我是一個黑客位的遺憾,並有其他人借用代碼位:/

<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> 

編輯:

感謝用戶:比亞夫-ferdy下面response.php現在與我的形式上面的代碼。對於原始代碼,還要感謝Audioprobe http://forum.loudcity.net/viewtopic.php?id=4160

<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> 
+0

你刪除某些條件或循環?或者爲什麼你的代碼中有'{'和'}'?它通常用於例如一個'if'語句:'if(condition){}'。你也可以描述**「表單似乎工作,但我有錯誤包含我的變量。**這是什麼不工作?你是否收到任何錯誤信息?如果你使用'var_dump($ _ GET [ 'titles'])''而不是'echo $ _GET ['titles']'? – ferdynator

+0

該表格似乎可行,但是我在包含我的變量時出錯了,這意味着我的HTML表單代碼似乎會導致期望的我的變量爲response.php'http://www.mysite.com/filelocation/response.php?titles = myvariable'。我會再回到你的其他問題 –

+0

我已經刪除了一條if語句。刪除所有大括號? –

回答

1

正如我在我的評論中寫到的,你應該刪除大括號,因爲它們在你的代碼中已經過時了。此外,在所有的線

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

刪除[]太行看起來就像這樣:

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

然後除去[$count]任何一次出現在你的代碼,因爲該變量不再使用。 最後但並非最不重要改變$titles$_GET['titles']在這一行:

curl_setopt($mysession, CURLOPT_URL, "http://".$serv["host"][$count].":".$serv["port"][$count]."/admin/metadata?mount=".$serv["mount"][$count]."&mode=updinfo&song=test".$titles); 
+0

感謝您提供的所有提示。我非常接近 也許如果我添加一個打印/寫入行來顯示y服務器的xml響應我可能能夠讀取錯誤是什麼。 我期望的響應是... –

+0

' 元數據更新成功 ' –

+0

的你響應主體請求可以經由'$含量= curl_exec($ MySession的)訪問' – ferdynator