[英]how do i insert a variable? from a form into a file_get_contents link
我如何將表單中的變量插入到file_get_contents(“ link + formdata”)中
通過表單提交的變量,包含句號,數字,字母
示例:danny.29將替換以下鏈接中的HERE:
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>
<?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或該變量的可接受值列表。
<?php echo file_get_contents("http://userapi.website.com/" . $x); ?>
點是串聯的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.