• Najnowsze pytania
  • Bez odpowiedzi
  • Zadaj pytanie
  • Kategorie
  • Tagi
  • Zdobyte punkty
  • Ekipa ninja
  • IRC
  • FAQ
  • Regulamin
  • Książki warte uwagi

Cześć mam problem z cURLem na datarejestracji.gov.pl

Cloud VPS
0 głosów
630 wizyt
pytanie zadane 23 marca 2021 w PHP przez Sebastian Szyja Bywalec (2,950 p.)
edycja 23 marca 2021 przez Comandeer

Hejka!

Mam taki kodzik:

<?php
  $url = "https://historiapojazdu.gov.pl/";
  $vin = "[cyk]";
  $numer_rejestracyjny = "[cyk]";
  $data_pierwszej_rejestracji = date("[cyk]");

  function curl($url) {
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  	curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);

    $content = curl_exec($curl);
    $resultUrl = explode('<form id="_historiapojazduportlet_WAR_historiapojazduportlet_:formularz" name="_historiapojazduportlet_WAR_historiapojazduportlet_:formularz" method="post" action="', $content);
    $resultUrl = explode('"', $resultUrl[1]);

    $resultViewState = explode('<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="', $content);
    $resultViewState = explode('"', $resultViewState[1]);

    $postUrl = $resultUrl[0];
    $viewState = $resultViewState[0];
  	return array("postURL"=>$postUrl, "javax.faces.ViewState"=>$viewState);
  }

  function sendPost($url, $numerRejestracyjny, $numerVIN, $dataPierwszejRejestracji) {
    $array = curl($url);
    $encodedUrl = "https://historiapojazdu.gov.pl/strona-glowna?p_p_id=historiapojazduportlet_WAR_historiapojazduportlet&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_cacheability=cacheLevelPage&p_p_col_id=column-1&p_p_col_count=1&_historiapojazduportlet_WAR_historiapojazduportlet__jsfBridgeAjax=true&_historiapojazduportlet_WAR_historiapojazduportlet__facesViewIdResource=%2Fviews%2Findex.xhtml&_historiapojazduportlet_WAR_historiapojazduportlet_javax.faces.ViewState=".urlencode($array['javax.faces.ViewState'])."&_historiapojazduportlet_WAR_historiapojazduportlet_:vin=".urlencode($numerVIN)."&_historiapojazduportlet_WAR_historiapojazduportlet_:data=".urlencode($dataPierwszejRejestracji)."&_historiapojazduportlet_WAR_historiapojazduportlet_amp;p_p_lifecycle=2&_historiapojazduportlet_WAR_historiapojazduportlet_:rej=".urlencode($numerRejestracyjny)."&_historiapojazduportlet_WAR_historiapojazduportlet_:formularz=_historiapojazduportlet_WAR_historiapojazduportlet_%3Aformularz&_historiapojazduportlet_WAR_historiapojazduportlet_amp;p_p_mode=view&_historiapojazduportlet_WAR_historiapojazduportlet_amp;p_p_cacheability=cacheLevelPage&_historiapojazduportlet_WAR_historiapojazduportlet_let__jsfBridgeAjax=true&_historiapojazduportlet_WAR_historiapojazduportlet__facesViewIdRender=%2Fviews%2Findex.xhtml&_historiapojazduportlet_WAR_historiapojazduportlet_amp;p_p_col_id=column-1&_historiapojazduportlet_WAR_historiapojazduportlet_amp;p_p_state=normal&_historiapojazduportlet_WAR_historiapojazduportlet_amp;p_p_col_count=1&_historiapojazduportlet_WAR_historiapojazduportlet_let__facesViewIdResource=%2Fviews%2Findex.xhtml&_historiapojazduportlet_WAR_historiapojazduportlet_javax.faces.encodedURL=https%3A%2F%2Fhistoriapojazdu.gov.pl%2Fstrona-glowna%3Fp_p_id%3Dhistoriapojazduportlet_WAR_historiapojazduportlet";
    $fields = array (
                        'javax.faces.ViewState'=> urlencode($array['javax.faces.ViewState']),
                        '_historiapojazduportlet_WAR_historiapojazduportlet_:rej'=> urlencode($numerRejestracyjny),
                        '_historiapojazduportlet_WAR_historiapojazduportlet_:vin'=> urlencode($numerVIN),
                        '_historiapojazduportlet_WAR_historiapojazduportlet_:data'=> urlencode($dataPierwszejRejestracji),
                        '_historiapojazduportlet_WAR_historiapojazduportlet_:formularz'=> urlencode("_historiapojazduportlet_WAR_historiapojazduportlet_:formularz")
                    );
    $fields_string = "";
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    rtrim($fields_string, '&');

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $array['postURL']);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  	curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  	curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60);
    curl_setopt($curl, CURLOPT_POST, count($fields));
    curl_setopt($curl, CURLOPT_POSTFIELDS, $fields_string);
    $content = curl_exec($curl);

  	return $content;
  }

  //zmienne do przesłania
    //method="post"
    //action=$postUrl
    //enctype="application/x-www-form-urlencoded"

  print sendPost($url, $numer_rejestracyjny, $vin, $data_pierwszej_rejestracji);

?>

Macie jakieś pomysły dlaczego tak jest? :(((

komentarz 23 marca 2021 przez Comandeer Guru (607,100 p.)
Ale jak jest?

Przy okazji wyciąłem z kodu dane wrażliwe. Proszę nie umieszczać takich na publicznym forum!
komentarz 23 marca 2021 przez Sebastian Szyja Bywalec (2,950 p.)
Ahhhh... treść pytania się nie załadowała .....
komentarz 23 marca 2021 przez Sebastian Szyja Bywalec (2,950 p.)
Sorry za wrażliwe dane ://
komentarz 23 marca 2021 przez Sebastian Szyja Bywalec (2,950 p.)

Pewnie wysłałem źle jakąś daną albo ją pominąłem nie mam pojęcia :(( Taki komunikat:

Zaloguj lub zarejestruj się, aby odpowiedzieć na to pytanie.

Podobne pytania

0 głosów
2 odpowiedzi 1,496 wizyt
0 głosów
2 odpowiedzi 604 wizyt
pytanie zadane 10 lipca 2023 w PHP przez lalanablanalala Bywalec (2,090 p.)
0 głosów
1 odpowiedź 850 wizyt
pytanie zadane 19 lipca 2019 w PHP przez Bartosz Pawlak Początkujący (370 p.)

93,488 zapytań

142,421 odpowiedzi

322,772 komentarzy

62,906 pasjonatów

Motyw:

Akcja Pajacyk

Pajacyk od wielu lat dożywia dzieci. Pomóż klikając w zielony brzuszek na stronie. Dziękujemy! ♡

Oto polecana książka warta uwagi.
Pełną listę książek znajdziesz tutaj

Kursy INF.02 i INF.03
...