How to get input value from another site when opening a page? When opening the page I load the file get.php which takes the value input from another site. JS I deduce the received value, but deduces nothing. Where am I wrong?

File get.php

 <?php $str = file_get_contents("https://ecom.akbars.ru/cgi-bin/cgi_link?TERMINAL=93200011"); preg_match('/<input type="hidden" value="(.*)" id="Form_id" name="FORM_ID"/', $str, $matches); echo $matches[1]; 

JavaScript to display the results:

 <?php include 'get.php'; ?> <script> $.get('get.php', {}, function(data){ alert('значение'); alert(data);}); </script> 

    2 answers 2

    You have a regular is wrong. Try this:

     /<input type="hidden" class="txt" id="Form_id" name="FORM_ID"\svalue="(.*)"/im 

    As for the cropped line, I tried it like through your file_get_contents, really another line substitutes. I tried using curl - it helped, it returns a normal string

     $url = 'https://ecom.akbars.ru/cgi-bin/cgi_link?TERMINAL=93200011'; function get_url($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.17) Gecko/2009122116 Firefox/3.0.17"); $headers = array ( 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8', 'Accept-Language: ru,en-us;q=0.7,en;q=0.3', 'Accept-Charset: windows-1251, utf-8;q=0.7,*;q=0.7' ); curl_setopt($ch, CURLOPT_HTTPHEADER,$headers); curl_setopt($ch, CURLOPT_REFERER, "google.com"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $result = curl_exec($ch); // выполняем запрос curl curl_close($ch); return $result; } $data = get_url($url); 

    I suspect that the matter is in the headlines, but did not check in which ones.

    • but do not tell me what it is / im mean? - Aslero
    • one
      I'll tell you. i - case-insensitive search. and m is a multi-string search. in general you can read at the docks - Rochfort
    • and another question, everything is output- just super, but at the end it writes two signs == and if you look at the site where form_id, then there are more characters than it gives me - Aslero
    • brings you from a site by a company
    • and on the other site like this 7MMJMxBxue2VXZGgNvpeaKTho0ZTE5411NSAo0vkaBoKqTeuuBcLY4ADrf4pNuPAMPQZrzyd6GudIqXq4dgZzUdQEoGU0nfqW2wZ0BZQ2QC4IPcv117j + + 9FG4aApmXP8iuS48rvO41GvWvSraz 8qCVF8QUJst0 + 9LWPVABBj kONqwr + / + mMqEx2ctqAaekvsmPb3febAa2KI5swSzKp9ehsDLb6p0tqUQUDNkuk42IfkFBoQd6MOARRlW0X25EyCs8fawj90KkfmYUhCpeKkVBy1iqphRiF5 / tC5MmFWLEARxCKY0pSizFvZRq2DXplZS0Qc09pgD + VVSAH / dQ1cMv dxUuLnwNE6lHB0lBuPfXbOPMlW872o + + + udyP2u i0lRIGuaYiWOtE7f5TmXPCLxEsqcDKAOx1aeytJH3mMPsXIx9Qli1dYyJXEgqSZ5OxFcyxS46h - Aslero

    In general, there is an interesting, but the old library PHP Simple HTML DOM Parser for parsing html and working with it like jquery, is very convenient. But generally try to ask api from a resource that you want to parse), and then parsing is resource intensive and if there is a chance to avoid it, then why not try?) Link to an article about this library