Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我可以将HTML表单数据传递给PHP并使用PHP吗;邮政「;数据?_Php_Html - Fatal编程技术网

我可以将HTML表单数据传递给PHP并使用PHP吗;邮政「;数据?

我可以将HTML表单数据传递给PHP并使用PHP吗;邮政「;数据?,php,html,Php,Html,我正在使用这个蹩脚的API,它提供了一个apptoken作为URL的一部分,用于表单的操作位。方法是post。我想做的是尝试将apptoken隐藏在源代码中(这不是真的必要,但现在我想知道我正在尝试做的是否可能),因此我的想法是将表单操作设置为HTML表单,将其设置为function.php,并将表单操作发布到 php将不会公开可读,因此像内容管理系统配置文件一样隐藏apptoken 这可能吗?还是我在追一只兔子下错洞。。。我只需要被指向正确的方向 编辑: HTML格式: <h2>C

我正在使用这个蹩脚的API,它提供了一个apptoken作为URL的一部分,用于表单的操作位。方法是post。我想做的是尝试将apptoken隐藏在源代码中(这不是真的必要,但现在我想知道我正在尝试做的是否可能),因此我的想法是将表单操作设置为HTML表单,将其设置为function.php,并将表单操作发布到

php将不会公开可读,因此像内容管理系统配置文件一样隐藏apptoken

这可能吗?还是我在追一只兔子下错洞。。。我只需要被指向正确的方向

编辑: HTML格式:

<h2>Client Tracker: Sample Clients</h2><form name=qdbform method=POST onsubmit='return validateForm(this)' encType='multipart/form-data' action=https://sample.quickbase.com/db/bdrsrxjnrr?act=API_AddRecord&apptoken=cwfcy7gdzsjeo6556ebi2bn4u4kr>
<input type=hidden name=fform value=1>
<table>
<tr><td class=m>Company</td>
<td class=m><input type=text size=40 name=_fid_5 ></td></tr>
<tr><td class=m>Contact</td>
<td class=m><input type=text size=40 name=_fid_10 ></td></tr>
<tr><td class=m>Comments</td>
<td class=m><textarea  name=_fid_12 rows=6 cols=40></textarea></td></tr>
</table><input type=hidden name=rdr value='http://bbc.co.uk'>
<input type=submit value=Save>
</form>
<script lang=javascript>
function validateForm(theForm)
{
}
</script>
客户端跟踪器:示例客户端
单位
接触
评论
函数validateForm(表单)
{
}

所以-这里的位:
动作=https://sample.quickbase.com/db/bdrsrxjnrr?act=API_AddRecord&apptoken=cwfcy7gdzsjeo6556ebi2bn4u4kr>
我想通过查看源代码,让别人看不见我。我想到的方法是让web服务器在服务器端处理它,这样web用户就永远看不到数据实际上被发送到了什么地方,除了function.php或我称之为的任何东西。

您可以使用以下代码段在不使用curl的情况下执行此操作。只需将您的信息填充到数据数组中,就可以在不显示api或操作URL的情况下发布

$url = 'ENTER_ACTION_HERE';
$data = array('key1' => 'value1', 'key2' => 'value2');

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }

var_dump($result);

您可以使用以下代码段在不使用curl的情况下执行此操作。只需将您的信息填充到数据数组中,就可以在不显示api或操作URL的情况下发布

$url = 'ENTER_ACTION_HERE';
$data = array('key1' => 'value1', 'key2' => 'value2');

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }

var_dump($result);

概括地说,你是这样做的。您已将表单提交到
send.php

<form name="qdbform" method="post" onsubmit="return validateForm(this)" action="send.php">

概括地说,你是这样做的。您已将表单提交到
send.php

<form name="qdbform" method="post" onsubmit="return validateForm(this)" action="send.php">

以下是如何发送请求和接收响应:

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $url,
    CURLOPT_POST => true,
    // or this for a custom HTTP method
//  CURLOPT_CUSTOMREQUEST => $method,
    // i.e. ['Content-Type: application/json']
    CURLOPT_HTTPHEADER => $headers,
    // send your POST data here; if it's an array use urlencode around it
    CURLOPT_POSTFIELDS => $body,
    // executing the cURL operation returns a string containing the full response
    CURLOPT_RETURNTRANSFER => true,
    // retrieve the headers too
    CURLOPT_HEADER => true,
    // you may or may not want this; some servers have problems
    CURLOPT_SSL_VERIFYPEER => true,
    CURLOPT_CONNECTTIMEOUT => 5,
]);

$response = curl_exec($curl);

if(empty($response)) {
    throw new Exception(curl_error($curl), curl_errno($curl));
}
有关如何解析响应的信息可在此处找到:


以下是如何发送请求和接收响应:

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $url,
    CURLOPT_POST => true,
    // or this for a custom HTTP method
//  CURLOPT_CUSTOMREQUEST => $method,
    // i.e. ['Content-Type: application/json']
    CURLOPT_HTTPHEADER => $headers,
    // send your POST data here; if it's an array use urlencode around it
    CURLOPT_POSTFIELDS => $body,
    // executing the cURL operation returns a string containing the full response
    CURLOPT_RETURNTRANSFER => true,
    // retrieve the headers too
    CURLOPT_HEADER => true,
    // you may or may not want this; some servers have problems
    CURLOPT_SSL_VERIFYPEER => true,
    CURLOPT_CONNECTTIMEOUT => 5,
]);

$response = curl_exec($curl);

if(empty($response)) {
    throw new Exception(curl_error($curl), curl_errno($curl));
}
有关如何解析响应的信息可在此处找到:


好的,既然您没有足够的实际代码,那么让我给您举一个简单的例子,让您了解问题和解决方案

  • 首先,创建一个新页面,比如secondpage.php来处理表单。此外,您不必在表单中添加任何
    隐藏的
    输入字段,服务器端PHP页面和cURL库将处理这些字段,稍后将对此进行解释。假设你的表格是这样的:

    <h2>Client Tracker: Sample Clients</h2>
    <form action="secondpage.php" method="POST" name="qdbform" onsubmit="return validateForm(this)" enctype="multipart/form-data">
        <table>
            <tr><td class="m">Company</td>
            <td class="m"><input type="text" size="40" name="_fid_5" /></td></tr>
            <tr><td class="m">Contact</td>
            <td class="m"><input type="text" size="40" name="_fid_10" /></td></tr>
            <tr><td class="m">Comments</td>
            <td class="m"><textarea name="_fid_12" rows="6" cols="40"></textarea></td></tr>
        </table>
        <input type="submit" name="submit" value="Save">
    </form>
    
    if(isset($_POST['submit'])){
        $url = "https://sample.quickbase.com/db/bdrsrxjnrr?act=API_AddRecord&apptoken=cwfcy7gdzsjeo6556ebi2bn4u4kr";
        $data = array('_fid_5' => $_POST['_fid_5'], '_fid_10' => $_POST['_fid_10'], '_fid_12' => $_POST['_fid_12']);
    
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        $response = curl_exec($ch);
        curl_close($ch);
    }
    

这里有几点需要注意

  • CURLOPT_RETURNTRANSFER
    设置为
    true
    以将传输作为
    curl_exec()
    的返回值字符串返回,而不是直接输出
  • CURLOPT\u SSL\u VERIFYPEER
    可用于验证对等方的证书。如果我们将其指定为
    false
    ,它将接受任何服务器(对等)证书
  • CURLOPT_POST
    用于执行常规HTTP POST。这篇文章是普通的
    应用程序/x-www-form-urlencoded
    类型,HTML表单最常用
  • CURLOPT_POSTFIELDS
    用于指定我们希望随此POST请求提交的完整数据。应使用函数将
    $data
    数组转换为URL编码的查询字符串,以便将其作为
    application/x-www-form-urlencoded
    发送
好的,既然您没有足够的实际代码,那么让我给您举一个简单的示例,让您了解问题和解决方案

  • 首先,创建一个新页面,比如secondpage.php来处理表单。此外,您不必在表单中添加任何
    隐藏的
    输入字段,服务器端PHP页面和cURL库将处理这些字段,稍后将对此进行解释。假设你的表格是这样的:

    <h2>Client Tracker: Sample Clients</h2>
    <form action="secondpage.php" method="POST" name="qdbform" onsubmit="return validateForm(this)" enctype="multipart/form-data">
        <table>
            <tr><td class="m">Company</td>
            <td class="m"><input type="text" size="40" name="_fid_5" /></td></tr>
            <tr><td class="m">Contact</td>
            <td class="m"><input type="text" size="40" name="_fid_10" /></td></tr>
            <tr><td class="m">Comments</td>
            <td class="m"><textarea name="_fid_12" rows="6" cols="40"></textarea></td></tr>
        </table>
        <input type="submit" name="submit" value="Save">
    </form>
    
    if(isset($_POST['submit'])){
        $url = "https://sample.quickbase.com/db/bdrsrxjnrr?act=API_AddRecord&apptoken=cwfcy7gdzsjeo6556ebi2bn4u4kr";
        $data = array('_fid_5' => $_POST['_fid_5'], '_fid_10' => $_POST['_fid_10'], '_fid_12' => $_POST['_fid_12']);
    
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        $response = curl_exec($ch);
        curl_close($ch);
    }
    

这里有几点需要注意

  • CURLOPT_RETURNTRANSFER
    设置为
    true
    以将传输作为
    curl_exec()
    的返回值字符串返回,而不是直接输出
  • CURLOPT\u SSL\u VERIFYPEER
    可用于验证对等方的证书。如果我们将其指定为
    false
    ,它将接受任何服务器(对等)证书
  • CURLOPT_POST
    用于执行常规HTTP POST。这篇文章是普通的
    应用程序/x-www-form-urlencoded
    类型,HTML表单最常用
  • CURLOPT_POSTFIELDS
    用于指定我们希望随此POST请求提交的完整数据。应使用函数将
    $data
    数组转换为URL编码的查询字符串,以便将其作为
    application/x-www-form-urlencoded
    发送
是的,可以使用库。但是,除非你发布相关的代码,否则没有人可以回答你的问题。谢谢-这看起来很有趣。我已经添加了一些上下文的html代码。不幸的是,由于我还不知道php方面会是什么,这就是我作为一个例子所要展示的全部内容。希望这将解决您的问题。是的,使用库是可能的。但是,除非你发布相关的代码,否则没有人可以回答你的问题。谢谢-这看起来很有趣。我已经添加了一些上下文的html代码。不幸的是,由于我还不知道php方面会是什么,这就是我作为一个例子所要展示的全部内容。希望这能解决你的问题。我让它工作起来,并为错误处理建立了逻辑。@Meows很高兴能帮上忙。如果答案解决了您的问题,请接受。摇滚明星。我让它工作起来,并为错误处理建立了逻辑。@Meows很高兴能帮上忙。如果答案解决了您的问题,请接受。