joe joe - 1 year ago 94
Javascript Question

PHP curl form with no action and js events

I'm trying to use curl to post some data and retrieve it from a website that isn't mine, the websites form doesn't seem to have a form action and the page doesn't reload when you submit the data and there also seems to be some js behind the click of the button.

$url = "";

$parm = "numer=RR123456789PL";

and here is the curl:

CURLOPT_URL => $url,

I execute and init the curl as expected, just showing the important parts. Here is also the live http headers output:

POST /wssClient.php HTTP/1.1
Accept: */*
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36

HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Content-Length: 1215
Content-Type: text/html; charset=UTF-8
Date: Mon, 30 Jun 2014 03:31:59 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Server: Apache
X-Cnection: close

At the moment it just shows the page and it doesn't look like that form was submitted, I've also tried putting the url as: "" and just get told to enter the number.

Answer Source

In such cases you go to chrome, hit F12, go to network, submit the form and see what is sent to the server. I see this posted


If you view source you see

if (jQuery('#numer').val().length == 19) {
  var numer = dodajck(jQuery('#numer').val())
} else var numer = jQuery('#numer').val();

  type: 'post',
  cache: true,
  dataType: 'html',
  data: ({
    s: 'fggsbnqu033gqiipemr50fer56',
    n: numer,
    l: ''
url: 'wssClient.php',

The s:.... could mean you need to have a session on their server to be able to call the wssClient - if so, you will need to CURL with sessions

If you can call their server without a session or you have a session before you call you can curl using the parm is n= and not numer= and you need to have calculated the checksum using their function which can easily be translated to PHP

function dodajck(numer) {
    // dodatkowe sprawdzenia i określenie wag oraz części numeru, która
    // ma zostać zważona
    //String wagi;
    //String doWazenia;

    var wagi = "3131313131313131313";
    var doWazenia = String(numer);
    // wyliczenie sumy iloczynów waga * cyfra
    var suma = 0;
    for (var i = 0; i < 19; i++)
    suma = suma + Number(doWazenia.substring(i, i + 1)) * Number(wagi.substring(i, i + 1));
    // ostateczne sprawdzenia

    // przykład numeru 20-cyfrowego
    // 00
    // 1 - rodzaj?
    // 590 -- kraj 590 = PL
    // 0773 -- firma 0773 = PP
    // 3 -- rodzaj przesyłki
    // 12345678 - numer przesyłki
    // 9 - CK
    // ważone są numery od 1 do 19
    var ck = 10 - suma % 10;
    if (ck == 10) ck = 0;

    return String(numer) + String(ck);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download