2013-03-09 19 views
0

如何插入從表單變量成的file_get_contents(「鏈接+ FORMDATA」)我如何插入一個變量?從形式到的file_get_contents鏈接

變量正在通過表單提交,幷包含句號,數字,字母

實施例:danny.29將在下面的鏈接取代的位置:

的file_get_contents( 「http://userapi.website.com/HERE」);

正如你看到的我是很新的這一點,任何幫助將是非常讚賞:)

的index.html

<html> 
<body> 

<form action="add.php" method="post"> 
ID: <input type="text" name="add"> 
<input type="submit"> 
</form> 

</body> 
</html> 

add.php

<html> 
<body> 

<?php $x=$_POST['add'];?> 

<?php 
echo file_get_contents("http://userapi.website.com/"echo $x;"); 
?> 

<?php echo $_POST["file_get_contents"]; ?> 

</body> 
</html> 

回答

0
<?php echo file_get_contents("http://userapi.website.com/" . $x); ?> 

點爲concatenation

+0

您可以使用大括號在字符串中進行連接。 – 2013-03-09 12:33:30

1
<?php echo $_POST["file_get_contents"]; ?> 

沒有意義。 POST數組僅在第一次加載時包含add密鑰。

echo file_get_contents("http://userapi.website.com/". $x); 

會得到正確的地址頁的內容,而且把它記到你只需要做一個變量:

$var = file_get_contents("http://userapi.website.com/". $x); 

而且這個劇本是沒有絕對安全的。你應該總是驗證用戶輸入(在這種情況下你的POST變量)。我建議你使用REGEX或該變量的可接受值列表。

+0

建議編輯修復您的語法錯誤。 – 2013-03-09 12:29:58

+0

嘿,謝謝你,有一個問題是有語法/代碼錯誤嗎? http://i.imgur.com/gtskZmC.png似乎像缺少一些東西,因爲不會在線運行? – user2151111 2013-03-09 13:03:47

+0

@ user2151111,編輯。 – Shoe 2013-03-09 13:07:00