0

如何将表单中的变量插入 file_get_contents("link+formdata")

通过表单提交的变量,包含句号、数字、字母

示例:danny.29 将替换以下链接中的 HERE:

file_get_contents(" http://userapi.website.com/HERE ");

如您所见,我对此很陌生,非常感谢您提供任何帮助:)

索引.html

<html>
<body>

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

</body>
</html>

添加.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>
4

2 回答 2

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 或该变量的可接受值列表。

于 2013-03-09T12:28:41.507 回答
0
<?php echo file_get_contents("http://userapi.website.com/" . $x); ?>

点用于连接

于 2013-03-09T12:26:04.383 回答