0

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

Bernard Rosset
  • 4,523
  • 6
  • 27
  • 29

1 Answers1

0

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

Olivier Pons
  • 15,363
  • 26
  • 117
  • 213