Send post to another website and receive the result

2

On my server I have a checker that uses an external server to get a response, but that response is displayed on the external server and I want it to be displayed on my server.

How can I make this answer appear on my server?

The form you send is the following:

<form method="POST" action="chk.php" style="margin-top:2%">
    <p><input type="text" style="padding: 15px 10px 10px; font-weight: bold; font-size: 18px;font-family: 'Source Sans Pro',arial black,sans-serif; border: 1px solid #cecece;  color: black;box-sizing: border-box; width: 60%;  max-width: 450px;" name="imei" autocomplete="off" maxlength="30" placeholder="IMEI or Serial Number">



    <button onclick="ButtonClicked();  " type="submit" ;="" style="background-color: ; padding: 10px 25px;  border: 2px solid #b2b2b2; display: inline-block; cursor: pointer; width: 20%; max-width: 100px; color: #000000;"><font size="4,5">Search</font></button></form>

And this is the code I had planned to use to send and get the answer but I could not make it work because it does not teach me an answer, I just get an error.

<?php
$imei = utf8_decode($_POST['imei']);

//Lo primerito, creamos una variable iniciando curl, pasándole la url
$ch = curl_init('https://otraweb.com/chek.php');

//especificamos el POST (tambien podemos hacer peticiones enviando datos por GET
curl_setopt ($ch, CURLOPT_POST, 1);

//le decimos qué paramáetros enviamos (pares nombre/valor, también acepta un array)
curl_setopt ($ch, CURLOPT_POSTFIELDS, "imei=$imei");

//le decimos que queremos recoger una respuesta (si no esperas respuesta, ponlo a false)
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true)

//recogemos la respuesta
$respuesta = curl_exec ($ch);

//o el error, por si falla
$error = curl_error($ch);

//y finalmente cerramos curl
curl_close ($ch);
    
asked by juan valdez 09.04.2018 в 20:00
source

1 answer

-1

The error may be that you are on a different server Add this header to allow access from another source

<?php
header('Access-Control-Allow-Origin: *');

You can also specify a URL as the origin of the request instead of all (*)

more info: link

    
answered by 09.04.2018 в 21:57