dongzhao5834 2011-02-24 11:22
浏览 31

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

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 . "
";
       }

       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

  • 写回答

1条回答 默认 最新

  • dongyun6003 2011-11-18 08:56
    关注

    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()).

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。