在php中转换get到post
如何将此PHP代码从使用$\u GET方法转换为$\u POST在php中转换get到post,php,Php,如何将此PHP代码从使用$\u GET方法转换为$\u POST <?php if (isset($_GET['submit'])) { if (checkCreditCard ($_GET['CardNumber'], $_GET['CardType'], $ccerror, $ccerrortext)) { $ccerrortext = 'This card has a valid format'; } else { echo 'not working'; } } ?> 这是
<?php
if (isset($_GET['submit'])) {
if (checkCreditCard ($_GET['CardNumber'], $_GET['CardType'], $ccerror, $ccerrortext)) {
$ccerrortext = 'This card has a valid format';
} else {
echo 'not working';
}
}
?>
这是在表单端处理的。与其将“method”属性设置为GET,不如将其设置为POST 这将告诉它将其作为POST变量传递,从而消除GET给您的限制 就PHP而言,它不关心它是GET还是POST,只关心它需要知道在哪个数组中查找映射。即使如此,$\u REQUEST[]关联数组仍将同时在GET和POST数组中查找
如果您的好奇GET不仅使数据在URL中易于读取,还限制了您可以传递的数据大小(最大URL长度)数据如何到达它不是PHP的问题。您可能希望对POST方法请求使用表单或隐藏表单:
<form method="POST">
<input type="hidden" name="CardNumber" value="value">
</form>
您只需在脚本中的任何地方更改$\u GET to$\u POST即可。主要的变化在于数据的输入方式。这应该在将数据发送到此脚本的源页面中处理
让我们考虑一个简单的例子:
<!-- Login.html -->
<form method='POST' action='yourscript.php'>
Email<input type='text' name='email'></input>
Password<input type='password' name='password'></input>
</form>
电子邮件
密码
这里唯一的更改是method属性的'POST'参数代替'GET'将PHP代码更改为此(将$\u GET的所有实例更改为$\u POST):
将HTML表单开始标记从
更改为
(“…”表示标记中可能包含的其他属性)您只是指
<?php
if (isset($_POST['submit'])) {
if (checkCreditCard($_POST['CardNumber'], $_POST['CardType'], $ccerror, $ccerrortext)) {
$ccerrortext = 'This card has a valid format';
} else {
echo 'not working';
}
}
?>
尽管像其他人提到的那样,表单提交可能存在客户端问题…我可以为您编写此代码。我每小时收费100美元,最低计费时间为两小时,预付款。你有Paypal吗?做得好,没有检测到低音。
<?php
if (isset($_POST['submit'])) {
if (checkCreditCard($_POST['CardNumber'], $_POST['CardType'], $ccerror, $ccerrortext)) {
$ccerrortext = 'This card has a valid format';
} else {
echo 'not working';
}
}
?>