PHP伪造并跟踪来自PHP页面的表单帖子…cURL

PHP伪造并跟踪来自PHP页面的表单帖子…cURL,php,post,curl,Php,Post,Curl,我正在用PHP创建一个签出过程,有4个阶段/页面。每个页面收集关于用户etc的不同信息,第4阶段/页面是安全签出页面,该页面由外部托管,并接受来自第3阶段的POST表单提交 一切都会很好,但我需要验证阶段3中的数据,然后再将用户发送到外部阶段4,所以我研究了这一点,发现了这篇关于cURL的文章 所有看起来都很棒,但它似乎只是将数据发布到外部第4页,但我需要用户在同一时间实际被带到那里,以便他们看到第4页。我试过 header('Location: http://externalURLLink')

我正在用PHP创建一个签出过程,有4个阶段/页面。每个页面收集关于用户etc的不同信息,第4阶段/页面是安全签出页面,该页面由外部托管,并接受来自第3阶段的POST表单提交

一切都会很好,但我需要验证阶段3中的数据,然后再将用户发送到外部阶段4,所以我研究了这一点,发现了这篇关于cURL的文章

所有看起来都很棒,但它似乎只是将数据发布到外部第4页,但我需要用户在同一时间实际被带到那里,以便他们看到第4页。我试过

header('Location: http://externalURLLink');
…旋度连接关闭后立即关闭,但不起作用

显而易见的方法是有一个页面,基本上说现在点击这里进入我们的安全支付页面,但我不想这样做

有什么建议吗


谢谢

试试curl\u setopt$ch,CURLOPT\u FOLLOWLOCATION,真的

您可以尝试以下可能适合您的功能:

function curl_redir_exec($ch,$test = false)
    {
    static $curl_loops = 0;
    static $curl_max_loops = 20;
    if ($curl_loops++>= $curl_max_loops)
    {
    $curl_loops = 0;
    return FALSE;
    }
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $data = curl_exec($ch);
    list($header, $data) = explode("\n\n", $data, 2);
    $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($http_code == 301 || $http_code == 302)
    {
    $matches = array();
    preg_match('/Location:(.*?)\n/', $header, $matches);
    $url = @parse_url(trim(array_pop($matches)));
    if (!$url){
        //couldn't process the url to redirect to
        $curl_loops = 0;
        return $data;
    }
    $last_url = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL));
    if (!$url['scheme'])
    $url['scheme'] = $last_url['scheme'];
    if (!$url['host'])
    $url['host'] = $last_url['host'];
    if (!$url['path'])
        $url['path'] = $last_url['path'];
        $new_url = $url['scheme'] . '://' . $url['host'] . $url['path'] . ($url['query']?'?'.$url['query']:'');
        curl_setopt($ch, CURLOPT_URL, $new_url);
        return $this->curl_redir_exec($ch);
    } else {
        $curl_loops=0;
        if($test){
            return curl_getinfo($ch, CURLINFO_EFFECTIVE_URL).'<br />'.$http_code.'<br />'.$data;
        }else{
            return curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
        }
    }
}
您可以这样使用它:

$curl_session = curl_init($DESTINATION_URL);
curl_setopt($curl_session, CURLOPT_URL, $DESTINATION_URL);
curl_setopt($curl_session, CURLOPT_COOKIESESSION, 1);
curl_setopt($curl_session, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array('X-Forwarded-For: '.$_SERVER['REMOTE_ADDR']));
curl_setopt($curl_session, CURLOPT_VERBOSE, 1);
curl_setopt($curl_session, CURLOPT_POST, 1);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $POST_DATA);
curl_setopt($curl_session, CURLOPT_TIMEOUT, 30);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, FALSE);
$redirect_url = $shop->curl_redir_exec($curl_session);
if(curl_errno($curl_session))
{
    echo '<p>An error has occurred, please take note of the information below and contact support.</p>';
    echo "<br>Errno : ".curl_errno($curl_session) ."<br>";
    echo "<br>Error : ".curl_error($curl_session) ."<br>";
    die();
}
curl_close($curl_session);
header("location:$redirect_url");

希望这是有用的。

在显示给用户的页面中使用所需数据制作不可见表单,并用javascript提交。除了通过您的网站代理所有请求外,没有其他方法。这无助于用户使用浏览器自动登录。他想用php登录,然后让用户绕过浏览器中的身份验证表单。我尝试了这个方法,它将用户带到同一个页面,但似乎没有将他们链接到发布的数据。谢谢你。