我希望你能理解我的问题,只读我的代码片段。
我将解释我正在做什么:我想使用头部来编写URL,并在下面的PHP代码中打开网页
如何创建变量?
<form id=url type=get action='DATAPHP.PHP' accept-charset='UTF-8' >
<input type=text name=url size=50 value="" ><br><br>
<input type=submit name=url value="Enter Url">
</form>
<?php
$url = '';
$url = $_POST['url'];
echo get_remote_data($url,true); // FOLLOWLOCATION enabled; simple request;
?>我该如何修复这段代码?
发布于 2018-10-20 22:29:37
将信息从html或网页传递到php的最佳方式是通过表单。我将首先向你展示可能是最好的方法,那就是为html和php设置单独的页面,然后我会修改答案,这样你就可以把所有的代码-浏览器输出(即html)和php处理放在同一页,如果你喜欢这样做的话。
首先,使用单独的页面:
假设你在‘basicForm.html’中有一个类似这样的表单:
<form method="post" action="server_processing.php">
Name: <input type="text" name="nameInForm">
URL: <input type ="text" name="urlInForm">
<input type="submit" value="submit">
</form> 一旦用户提交表单,'server_processing.php‘页面将以POST数组的形式接收表单中的值,您可以像这样访问它:
<?php
if($_POST){// this checks for the existence of the $_POST array
//now we're assuming a form was submitted
$nameInForm = $_POST['name'];
$urlInForm = $_POST['url'];
echo ("Name entered: " . $nameInForm);
echo ("URL entered: " . $urlInForm);
}// if($_POST)...
?> 或者,您可以简单地在一个页面上完成所有这些工作(尽管分离代码会进一步简化代码的重用和可维护性):
<form>
Name: <input type="text" name="nameInForm">
URL: <input type ="text" name="urlInForm">
<input type="submit" value="submit">
</form>
<?php
if($_POST){// this checks for the existence of the $_POST array
//now we're assuming a form was submitted
$nameInForm = $_POST['name'];
$urlInForm = $_POST['url'];
echo ("Name entered: " . $nameInForm);
echo ("URL entered: " . $urlInForm);
}// if($_POST)...
?> https://stackoverflow.com/questions/52904884
复制相似问题