代码之家  ›  专栏  ›  技术社区  ›  fistameeny

PHP::Emulate<form method=“post”>,将用户转发到页面

  •  5
  • fistameeny  · 技术社区  · 17 年前

    PHP 链接到 Protx VSP Direct payment gateway cURL 图书馆,但似乎遇到了一个问题。我的代码如下:

    <?php  
    $ch = curl_init();  
    // Set the URL  
    curl_setopt($ch, CURLOPT_URL, 'http://www.google.com/');  
    // Perform a POST  
    curl_setopt($ch, CURLOPT_POST, 1);  
    // If not set, curl prints output to the browser  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);   
    // Set the "form fields"  
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);  
    $output = curl_exec($ch);  
    curl_close($ch);  
    ?>  
    

    所有这些都只是获取通过的URL的内容,而不会将用户转发到任何地方。我试着用谷歌搜索并尽可能多地阅读,但无法找出我遗漏了什么。有什么想法吗?如果可以避免的话,我不想创建一个自动提交的HTML表单。

    谢谢您的帮助:-)

    10 回复  |  直到 11 年前
        1
  •  2
  •   Manoj Sharma    9 年前

    3D安全API不允许您在后台执行请求。您需要将用户转发到3D安全站点。使用javascript自动提交表单。以下是我们的供应商的建议:

    <html> 
        <head> 
            <title>Processing your request...</title> 
        </head> 
        <body OnLoad="OnLoadEvent();"> 
            <form name="downloadForm" action="<%=RedirURL%>" method="POST"> 
                <noscript> 
                    <br> 
                    <br> 
                    <div align="center"> 
                        <h1>Processing your 3-D Secure Transaction</h1> 
                        <h2>JavaScript is currently disabled or is not supported by your browser.</h2><BR> 
                        <h3>Please click Submit to continue the processing of your 3-D Secure transaction.</h3><BR> 
                        <input type="submit" value="Submit"> 
                    </div> 
                </noscript> 
                <input type="hidden" name="PaReq" value="<%=PAREQ%>"> 
                <input type="hidden" name="MD" value="<%=TransactionID%>"> 
                <input type="hidden" name="TermUrl" value="<%=TermUrl%>"> 
            </form> 
            <SCRIPT LANGUAGE="Javascript"> 
                <!-- 
                function OnLoadEvent() { 
                    document.downloadForm.submit(); 
                } 
                //--> 
            </SCRIPT> 
        </body> 
    </html>
    
        2
  •  0
  •   stephenbayer    17 年前

        3
  •  0
  •   Jeremy Meo    17 年前

    要将用户重定向到PHP中的另一个页面,可以发送 header("Location: http://example.com/newpage"); . 然而,不幸的是,程序重定向会导致删除所有POST变量(出于安全原因)。如果要让用户的浏览器将POST请求发送到其他URL,则必须创建一个提交自身的表单:(

        4
  •  0
  •   fistameeny    17 年前

        5
  •  0
  •   Michael Ridley    17 年前

    您可以使用fsockopen()重定向到新网站,同时保留POST变量。关于如何实现这一点,有一个很好的教程 here .

    如果该网站被互联网怪物吃掉,我已经复制并粘贴了该功能,但我建议查看原始网站的上下文。

    function sendToHost($host,$method,$path,$data,$useragent=0)
    {
        // Supply a default method of GET if the one passed was empty
        if (empty($method)) {
            $method = 'GET';
        }
        $method = strtoupper($method);
        $fp = fsockopen($host, 80);
        if ($method == 'GET') {
            $path .= '?' . $data;
        }
        fputs($fp, "$method $path HTTP/1.1\r\n");
        fputs($fp, "Host: $host\r\n");
        fputs($fp,"Content-type: application/x-www-form- urlencoded\r\n");
        fputs($fp, "Content-length: " . strlen($data) . "\r\n");
        if ($useragent) {
            fputs($fp, "User-Agent: MSIE\r\n");
        }
        fputs($fp, "Connection: close\r\n\r\n");
        if ($method == 'POST') {
            fputs($fp, $data);
        }
    
        while (!feof($fp)) {
            $buf .= fgets($fp,128);
        }
        fclose($fp);
        return $buf;
    }
    
        6
  •  0
  •   fistameeny    17 年前

    啊,如果我误解了cURL的功能,我想我会满足于使用JS auto-submit的HTML表单。为我创造了更多的工作,但如果这是唯一的方法,我就不得不这么做。

    谢谢大家的帮助。

        7
  •  0
  •   MarkR    17 年前

    我认为在这种情况下,你需要使用一个表单。用户的浏览器需要访问卡支付公司网站,而不是服务器端代码。

        8
  •  0
  •   Nathan Strong    17 年前

    如果是这样,您只需在代码末尾添加以下内容:

    标题(“位置: http://www.yoursite.com/yoururl ");

    如果需要保存原始POST事务中的数据,请使用会话进行保存。

    对于无JS的解决方案来说,这应该是可行的。

        9
  •  0
  •   flungabunga    17 年前

    我已经为我曾经使用过的其他网站实现了类似的模式,它确实需要一些修改才能正确。

    http://en.wikipedia.org/wiki/Proxy_pattern

    祝你好运

        10
  •  0
  •   Chip Kaye    17 年前

    我发现上面的sendtoost()函数非常有用,但是源代码中有一个错误,需要花费一些时间进行调试:Content-type头值包含一个介于“form-”和“urlencoded”之间的空格,应该是“application/x-www-form-urlencoded”

    推荐文章