简体   繁体   中英

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

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

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

点是串联的

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM