如何使用 PHP 提交表单?

新手上路,请多包涵
<form style="text-align:center;" id="paypalform" action="https://www.paypal.com/cgi-bin/webscr" method="POST">
    <input type='hidden' name='cmd' value='_xclick'>
    <input type='hidden' name='business' value='payment@xxx.com'>
    <input type='hidden' name='item_name' value='201001114262121'>
    <input type='hidden' name='amount' id="amount" value='1.00'>
    <input type='hidden' name='currency_code' value='CAD'>
    <input type='hidden' name='return' value='http://www.xxx.com/paypal_process.php'>
    <input type='hidden' name='invoice' value='82'>
    <input type='hidden' name='charset' value='utf-8'>
    <input type='hidden' name='no_shipping' value='1'>
    <input type='hidden' name='no_note' value=''>
    <input type='hidden' name='notify_url' value='http://www.xxx.com/return.php'>
    <input type='hidden' name='rm' value='82'>
    <input type='hidden' name='cancel_return' value='http://www.xxx.com/index.html'>
</form>

有谁知道?

原文由 wp2 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 283
1 个回答
<?php
if(isset($_POST['submit']))
{
    function do_post_request($url, $data, $optional_headers = null)
    {
        $params = array('http' => array(
                        'method' => 'POST',
                        'content' => $data
                    ));
        if($optional_headers != null)
        {
            $params['http']['header'] = $optional_headers;
        }
        $ctx = stream_context_create($params);
        $fp = @fopen($url, 'rb', false, $ctx);
        if (!$fp)
        {
            throw new Exception("Problem with $url, $php_errormsg");
        }
        $response='';
        while (!feof($fp))
        {
            $response = $response.fgets($fp);
        }
        if ($response === false)
        {
            throw new Exception("Problem reading data from $url, $php_errormsg");
        }

        fclose($fp);
        return $response;
    }
    $host = 'http://mydomain.com';
    $url = 'http://mydomain.com/formHandler.php';
    $username = 'admin';
    $password = '123456';
    $data = array ('action' => 'login','lgname' => $username, 'lgpassword' => $password, 'format' => 'txt');
    $data = http_build_query($data);
    $reply = do_post_request($url, $data);
    echo "**********Response*********<pre>";
    echo var_dump($reply);
    #header('location:'.$host);
    #exit;

   } else {
       echo '<form method="post" enctype="multipart/form-data" action="'.$_SERVER['PHP_SELF'].'"><input type="text" name="uname" /><br><input type="password" name="password" /><input type="submit" name="submit"></form>';
   }

 ?>

尝试这个

原文由 Naresh 发布,翻译遵循 CC BY-SA 2.5 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏