如何使用PHP提交表单? [英] How to submit a form with PHP?

查看:61
本文介绍了如何使用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>

有人知道吗?

推荐答案

<?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>';
   }

 ?>

尝试一下

这篇关于如何使用PHP提交表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆