• 22-03-2021, 00:56:41
    #1
    Herkese iyi forumlar, php ile post işlemi gerçekleştiriyorum ve diğer php dosyasında file_get_contents ile post işleminin gerçekleştiği php dosyasından veri çekmeye çalışıyorum fakat postlanmış veriyi değil postlanmamış veriyi ekrana yazdırıyor.
    Postlanmış halini nasıl yazdırabilirim?

    tckimlik.php'deki kodlar:

    <?php
    
    $url = file_get_contents("https://xxxxxxxx.com/tckimlik/tckn.php");
    $json = json_decode($url,true);
    
    ?>
    
    <form action="#" method="POST">
    <label>Ad:</label><br>
    <input type="text" name="isim"><br>
    <label>Soyad:</label><br>
    <input type="text" name="soyisim"><br>
    <label>Doğum Yılı:</label><br>
    <input type="text" name="dgy"><br>
    <label>TC NO:</label><br>
    <input type="password" name="tc"><br>
    <input type="submit" value="Kontrol Et" />
    </form>
    <?php
    if($_POST){
    echo $json["message"]; //Şimdi amacım buradan doğru veriyi çektirmek. Fakat post edemiyor sanırım tckn.php dosyasına bu sebepten dolayı yanlış veriyi çekiyor. Yani TC doğruysa da WRONG yazdırıyor ekrana yanlışsa da WRONG yazdırıyor.
    }
    ?>
    tckn.php'deki kodlar:

    <?php
    
    if($_POST){
    $isim = $_POST["isim"];
    $soyisim = $_POST["soyisim"];
    $dgy = $_POST["dgy"];
    $tc = $_POST["tc"];
    }
    
    function tcno_dogrula($bilgiler){
    
    $gonder = '<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
    <TCKimlikNoDogrula xmlns="http://tckimlik.nvi.gov.tr/WS">
    <TCKimlikNo>'.$bilgiler["tcno"].'</TCKimlikNo>
    <Ad>'.$bilgiler["isim"].'</Ad>
    <Soyad>'.$bilgiler["soyisim"].'</Soyad>
    <DogumYili>'.$bilgiler["dogumyili"].'</DogumYili>
    </TCKimlikNoDogrula>
    </soap:Body>
    </soap:Envelope>';
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx" );
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt($ch, CURLOPT_POST, true );
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $gonder);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'POST /Service/KPSPublic.asmx HTTP/1.1',
    'Host: tckimlik.nvi.gov.tr',
    'Content-Type: text/xml; charset=utf-8',
    'SOAPAction: "http://tckimlik.nvi.gov.tr/WS/TCKimlikNoDogrula"',
    'Content-Length: '.strlen($gonder)
    ));
    $gelen = curl_exec($ch);
    curl_close($ch);
    
    return strip_tags($gelen);
    }
    
    // İşlemi gönder ve sonuç
    
    $bilgiler = array(
    "isim" => $isim,
    "soyisim" => $soyisim,
    "dogumyili" => $dgy,
    "tcno" => $tc
    );
    
    // Sonucu göster
    $sonuc = tcno_dogrula($bilgiler);
    
    if(!$_POST){
    
    if($sonuc=="true"){
    $myObj->status = "true";
    $myObj->message = "SUCCESS";
    $myJSON = json_encode($myObj);
    echo $myJSON;
    }else{
    $myObj->status = "false";
    $myObj->message = "WRONG";
    $myJSON = json_encode($myObj);
    echo $myJSON;
    }
    
    }
    
    ?>
  • 22-03-2021, 00:59:04
    #2
    $post = file_get_contents("php://input");
  • 22-03-2021, 10:29:43
    #3
    Üyeliği durduruldu
    tckn.php:

    <?php
    
    if (isset($_POST["isim"]) && isset($_POST["soyisim"]) && isset($_POST["dgy"]) && isset($_POST["tc"])) {
        $isim    = $_POST["isim"];
        $soyisim = $_POST["soyisim"];
        $dgy     = $_POST["dgy"];
        $tc      = $_POST["tc"];
    } else {
        $myObj          = new stdClass();
        $myObj->status  = "false";
        $myObj->message = "WRONG";
        $myJSON         = json_encode($myObj);
        echo $myJSON;
        die;
    }
    
    function tcno_dogrula($bilgiler)
    {
        $gonder = '<?xml version="1.0" encoding="utf-8"?>
            <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
            <soap:Body>
            <TCKimlikNoDogrula xmlns="http://tckimlik.nvi.gov.tr/WS">
            <TCKimlikNo>' . $bilgiler["tcno"] . '</TCKimlikNo>
            <Ad>' . $bilgiler["isim"] . '</Ad>
            <Soyad>' . $bilgiler["soyisim"] . '</Soyad>
            <DogumYili>' . $bilgiler["dogumyili"] . '</DogumYili>
            </TCKimlikNoDogrula>
            </soap:Body>
            </soap:Envelope>';
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $gonder);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'POST /Service/KPSPublic.asmx HTTP/1.1',
            'Host: tckimlik.nvi.gov.tr',
            'Content-Type: text/xml; charset=utf-8',
            'SOAPAction: "http://tckimlik.nvi.gov.tr/WS/TCKimlikNoDogrula"',
            'Content-Length: ' . strlen($gonder)
        ));
        $gelen = curl_exec($ch);
        curl_close($ch);
        
        return strip_tags($gelen);
    }
    
    // İşlemi gönder ve sonuç
    
    $bilgiler = array(
        "isim" => strip_tags($isim),
        "soyisim" => strip_tags($soyisim),
        "dogumyili" => strip_tags($dgy),
        "tcno" => strip_tags($tc)
    );
    
    // Sonucu göster
    $sonuc = tcno_dogrula($bilgiler);
    
    $myObj = new stdClass();
    if ($sonuc == "true") {
        $myObj->status  = "true";
        $myObj->message = "SUCCESS";
        $myJSON         = json_encode($myObj);
        echo $myJSON;
    } else {
        $myObj->status  = "false";
        $myObj->message = "WRONG";
        $myJSON         = json_encode($myObj);
        echo $myJSON;
    }
    tckimlik.php:
    <form action="" method="POST">
        <label>Ad:</label><br>
        <input type="text" name="isim"><br>
        <label>Soyad:</label><br>
        <input type="text" name="soyisim"><br>
        <label>Doğum Yılı:</label><br>
        <input type="text" name="dgy"><br>
        <label>TC NO:</label><br>
        <input type="password" name="tc"><br>
        <input type="submit" name="submit" value="Kontrol Et" />
    </form>
    
    <?php
    if(isset($_POST['submit'])) {
        $data = [
            'isim' => $_POST['isim'],
            'soyisim' => $_POST['soyisim'],
            'dgy' => $_POST['dgy'],
            'tc' => $_POST['tc']
        ];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'http://localhost/tckn.php');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        $response = curl_exec($ch);
        curl_close($ch);
        $result = json_decode($response, true);
        print $result['message'];
    }
    ?>
  • 22-03-2021, 12:29:43
    #4
    form post işlemlerinde $_POST kullanmanız gerekli arkadaşın verdiği örnekteki gibi. file_get_contents ile dosya içeriğini ya da dosyaya gelen RAW_POST u alabilirsiniz, json data gibi.
  • 22-03-2021, 14:26:47
    #5
    awoken adlı üyeden alıntı: mesajı görüntüle
    tckn.php:

    <?php
    
    if (isset($_POST["isim"]) && isset($_POST["soyisim"]) && isset($_POST["dgy"]) && isset($_POST["tc"])) {
        $isim    = $_POST["isim"];
        $soyisim = $_POST["soyisim"];
        $dgy     = $_POST["dgy"];
        $tc      = $_POST["tc"];
    } else {
        $myObj          = new stdClass();
        $myObj->status  = "false";
        $myObj->message = "WRONG";
        $myJSON         = json_encode($myObj);
        echo $myJSON;
        die;
    }
    
    function tcno_dogrula($bilgiler)
    {
        $gonder = '<?xml version="1.0" encoding="utf-8"?>
            <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
            <soap:Body>
            <TCKimlikNoDogrula xmlns="http://tckimlik.nvi.gov.tr/WS">
            <TCKimlikNo>' . $bilgiler["tcno"] . '</TCKimlikNo>
            <Ad>' . $bilgiler["isim"] . '</Ad>
            <Soyad>' . $bilgiler["soyisim"] . '</Soyad>
            <DogumYili>' . $bilgiler["dogumyili"] . '</DogumYili>
            </TCKimlikNoDogrula>
            </soap:Body>
            </soap:Envelope>';
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://tckimlik.nvi.gov.tr/Service/KPSPublic.asmx");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $gonder);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'POST /Service/KPSPublic.asmx HTTP/1.1',
            'Host: tckimlik.nvi.gov.tr',
            'Content-Type: text/xml; charset=utf-8',
            'SOAPAction: "http://tckimlik.nvi.gov.tr/WS/TCKimlikNoDogrula"',
            'Content-Length: ' . strlen($gonder)
        ));
        $gelen = curl_exec($ch);
        curl_close($ch);
        
        return strip_tags($gelen);
    }
    
    // İşlemi gönder ve sonuç
    
    $bilgiler = array(
        "isim" => strip_tags($isim),
        "soyisim" => strip_tags($soyisim),
        "dogumyili" => strip_tags($dgy),
        "tcno" => strip_tags($tc)
    );
    
    // Sonucu göster
    $sonuc = tcno_dogrula($bilgiler);
    
    $myObj = new stdClass();
    if ($sonuc == "true") {
        $myObj->status  = "true";
        $myObj->message = "SUCCESS";
        $myJSON         = json_encode($myObj);
        echo $myJSON;
    } else {
        $myObj->status  = "false";
        $myObj->message = "WRONG";
        $myJSON         = json_encode($myObj);
        echo $myJSON;
    }
    tckimlik.php:
    <form action="" method="POST">
        <label>Ad:</label><br>
        <input type="text" name="isim"><br>
        <label>Soyad:</label><br>
        <input type="text" name="soyisim"><br>
        <label>Doğum Yılı:</label><br>
        <input type="text" name="dgy"><br>
        <label>TC NO:</label><br>
        <input type="password" name="tc"><br>
        <input type="submit" name="submit" value="Kontrol Et" />
    </form>
    
    <?php
    if(isset($_POST['submit'])) {
        $data = [
            'isim' => $_POST['isim'],
            'soyisim' => $_POST['soyisim'],
            'dgy' => $_POST['dgy'],
            'tc' => $_POST['tc']
        ];
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'http://localhost/tckn.php');
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        $response = curl_exec($ch);
        curl_close($ch);
        $result = json_decode($response, true);
        print $result['message'];
    }
    ?>

    Teşekkürler, rica etsem yorumunuzu silebilir misiniz? Daha doğrusu yorum silinemediği için yorumunuzu değiştirip kodları siler misiniz?
  • 22-03-2021, 14:35:11
    #6
    Üyeliği durduruldu
    Silmem için bir sebep var ise direkt yorumu silerim tabi.