how do i insert a variable? from a form into a file_get_contents link

旧城冷巷雨未停 提交于 2019-12-12 03:45:35

问题


how do i insert a variable from a form into a file_get_contents("link+formdata")

the variable being submitted via a form and contains full stops,Numbers,letter

Example: danny.29 would replace HERE in the link below:

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

As you can see i'm very new to this, any help would be very much appreciated :)

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>

回答1:


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

Dot is for concatenation




回答2:


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

doesn't make sense. The POST array will only contain the add key on the first load.

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

will get correctly the content of the address page but to memorize it into a variable you just have to do:

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

Also this script is no totally secure. You should always validate user input (your POST variable in this case). I'd suggest you to use a REGEX or a list of acceptable values for that variable.



来源:https://stackoverflow.com/questions/15310614/how-do-i-insert-a-variable-from-a-form-into-a-file-get-contents-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!