如何通过 PHP GET/POST 获取内容来绕过 JavaScript 重定向

发布于 2024-10-19 04:09:57 字数 3522 浏览 1 评论 0 原文

我尝试通过 此表单收集 domme 信息 (NOTAM)< /a> 通过 PHP。

问题是,该网站使用 JavaScript 重定向来处理 POST 请求 2 次(在 链接 1 然后在表单地址上(使用 POST),然后再次将用户重定向到表单地址(使用 GET)。

我使用 Firefox Live HTTP Headers 扩展来收集请求并尝试欺骗发送的标头(本质上是 POST 的 Content-Type、Content-Length,甚至是非标准标头时的 Accept 和 Referer),

这是代码

第一个请求(POST)。 )

<?php
// POST form fields definition
$donnees = array(
'bResultat' => 'true',
'bImpression' => '',
'ModeAffichage' => 'COMPLET',
'AERO_Date_DATE' => date("Y").'/'.date("m").'/'.date("d"),
'AERO_Date_HEURE' => date("H").':'.((date("i")+10 >= 60) ? 60-date("i")+10 : date("i")+10),
'AERO_Langue' => 'FR',
'AERO_Duree' => '12',
'AERO_CM_REGLE' => '1',
'AERO_CM_GPS' => '2',
'AERO_CM_INFO_COMP' => '1',
'AERO_Tab_Aero[0]' => 'LFQQ',
'AERO_Tab_Aero[1]' => '',
'AERO_Tab_Aero[2]' => '',
'AERO_Tab_Aero[3]' => '',
'AERO_Tab_Aero[4]' => '',
'AERO_Tab_Aero[5]' => '',
'AERO_Tab_Aero[6]' => '',
'AERO_Tab_Aero[7]' => '',
'AERO_Tab_Aero[8]' => '',
'AERO_Tab_Aero[9]' => '',
'AERO_Tab_Aero[10]' => '',
'AERO_Tab_Aero[11]' => ''
);


// Headers encoding function definition
function http_build_headers( $headers ) {

       $headers_brut = '';

       foreach( $headers as $nom => $valeur ) {
               $headers_brut .= $nom . ': ' . $valeur . "\r\n";
       }

       return $headers_brut;
}

// Raw request content creation
$contenu = http_build_query( $donnees );
var_dump($contenu);
echo "<br/>=============<br/>";

// Headers definition
$headers = http_build_headers(
    array(
        'Referer' => 'http://notamweb.aviation-civile.gouv.fr/Script/IHM/Com_Chargement.php?URL=Bul_Aerodrome.php',
        'Content-Type' => 'application/x-www-form-urlencoded',
        'Content-Length' => strlen($contenu)
    )
);
echo strlen($contenu)."<br />=============<br/>";

// Context definition
$options = array(
    'http' => array(
        'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13',
        'method' => 'POST',
        'content' => $contenu,
        'header' => $headers
    )
);

// Context creation
$contexte = stream_context_create( $options );

// Sends POST form
$retour = file_get_contents( 'http://notamweb.aviation-civile.gouv.fr/Script/IHM/Bul_Aerodrome.php?AERO_Langue=FR', false, $contexte );

第二个请求(GET)如下:

// Headers definition
$headers = http_build_headers(
    array(
        'Accept' => 'text/css,*/*;q=0.1',
        'Referer' => 'http://notamweb.aviation-civile.gouv.fr/Script/IHM/Bul_Aerodrome.php?AERO_Langue=FR'
    )
);

// Context definition
$options = array(
    'http' => array(
        'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13',
        'method' => 'GET',
        'header' => $headers
    )
);

// Context creation
$contexte = stream_context_create( $options );

// Sends GET request
$retour = file_get_contents( 'http://notamweb.aviation-civile.gouv.fr/Script/IHM/Bul_Aerodrome.php?AERO_Langue=FR', false, $contexte );

var_dump($retour);
?>

JavaScript 重定向?或者有其他方法可以实现它吗?

我认为我的问题很明显:PHP 如何检测和管理此类

I try to collect domme information (NOTAM) on this form through PHP.

The problem is, the website uses JavaScript redirection to process the POST request 2 times (on link 1 then on the form address (using POST), then redirects the user to form address again (using GET).

I used the Firefox Live HTTP Headers extension to collect the log of the requests and tried to spoof the sent headers (essentially Content-Type, Content-Length for POST, and even Accept and Referer when non-standard ones).

I'm using the PHP file_get_contents method.

Here is the code:

First request (POST)

<?php
// POST form fields definition
$donnees = array(
'bResultat' => 'true',
'bImpression' => '',
'ModeAffichage' => 'COMPLET',
'AERO_Date_DATE' => date("Y").'/'.date("m").'/'.date("d"),
'AERO_Date_HEURE' => date("H").':'.((date("i")+10 >= 60) ? 60-date("i")+10 : date("i")+10),
'AERO_Langue' => 'FR',
'AERO_Duree' => '12',
'AERO_CM_REGLE' => '1',
'AERO_CM_GPS' => '2',
'AERO_CM_INFO_COMP' => '1',
'AERO_Tab_Aero[0]' => 'LFQQ',
'AERO_Tab_Aero[1]' => '',
'AERO_Tab_Aero[2]' => '',
'AERO_Tab_Aero[3]' => '',
'AERO_Tab_Aero[4]' => '',
'AERO_Tab_Aero[5]' => '',
'AERO_Tab_Aero[6]' => '',
'AERO_Tab_Aero[7]' => '',
'AERO_Tab_Aero[8]' => '',
'AERO_Tab_Aero[9]' => '',
'AERO_Tab_Aero[10]' => '',
'AERO_Tab_Aero[11]' => ''
);


// Headers encoding function definition
function http_build_headers( $headers ) {

       $headers_brut = '';

       foreach( $headers as $nom => $valeur ) {
               $headers_brut .= $nom . ': ' . $valeur . "\r\n";
       }

       return $headers_brut;
}

// Raw request content creation
$contenu = http_build_query( $donnees );
var_dump($contenu);
echo "<br/>=============<br/>";

// Headers definition
$headers = http_build_headers(
    array(
        'Referer' => 'http://notamweb.aviation-civile.gouv.fr/Script/IHM/Com_Chargement.php?URL=Bul_Aerodrome.php',
        'Content-Type' => 'application/x-www-form-urlencoded',
        'Content-Length' => strlen($contenu)
    )
);
echo strlen($contenu)."<br />=============<br/>";

// Context definition
$options = array(
    'http' => array(
        'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13',
        'method' => 'POST',
        'content' => $contenu,
        'header' => $headers
    )
);

// Context creation
$contexte = stream_context_create( $options );

// Sends POST form
$retour = file_get_contents( 'http://notamweb.aviation-civile.gouv.fr/Script/IHM/Bul_Aerodrome.php?AERO_Langue=FR', false, $contexte );

Second request (GET) following:

// Headers definition
$headers = http_build_headers(
    array(
        'Accept' => 'text/css,*/*;q=0.1',
        'Referer' => 'http://notamweb.aviation-civile.gouv.fr/Script/IHM/Bul_Aerodrome.php?AERO_Langue=FR'
    )
);

// Context definition
$options = array(
    'http' => array(
        'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13',
        'method' => 'GET',
        'header' => $headers
    )
);

// Context creation
$contexte = stream_context_create( $options );

// Sends GET request
$retour = file_get_contents( 'http://notamweb.aviation-civile.gouv.fr/Script/IHM/Bul_Aerodrome.php?AERO_Langue=FR', false, $contexte );

var_dump($retour);
?>

I thought my question was obvious: how can PHP detect and manage such JavaScript redirections? Is there a trick to bypass them? Or any other mean to achieve it?

Thanks a lot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转角预定愛 2024-10-26 04:09:57

答案很简单:Php 根本无法检测和管理 JavaScript 重定向。

您必须了解 JavaScript 在页面上执行的操作,并编写一些 Php 代码来“模拟”JavaScript 会执行的操作(在您的情况下,有点“猜测”存在重定向并执行另一个 file_get_contents()< /代码>)。

The answer is simple: Php can't detect and manage JavaScript redirections at all.

You'll have to understand what the JavaScript does on the page, and write some Php code that 'simulates' what the JavaScript would have done (in your case kindof "guess" there's a redirection and do another file_get_contents()).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文