Good morning of stackoverflow. I'm going through a problem that I can not see the light of solution. I have the following situation: I'm working on a portal, and this portal, I needed to send information to the site in our headquarters. So, it does a select, in that select, it is sent via cURL to the form of the other site, until that perfect, only that this site has a captcha that has been locking me a few days.
So, my headmistress said here, you do not need to submit the form, you can just fill it out. I'd like to know if it's possible to do something like that, fill an external form with the information you need, even before it was my original idea.
For example, take the id and fill in the value.
$("#User_institution").val(valorQualquer) //no success do ajax.
If it is not possible to do this, I want to know if it is possible to get the generated captcha when I send the POST in cURL and send it as if it were someone filling the captcha.
Att
Request for page loading data and retrieving json
$.ajax({
type: 'POST',
url: 'load-data.php?id='+id,
dataType: 'text',
success: function(data) {
msg = data;
var values = $.parseJSON(msg);
nomeEmpresa = values[0].razao_social;
emailEmpresa = values[0].email_comercial;
telefone = values[0].tel_comercial;
site = values[0].siteweb;
rua = values[0].end_logradouro;
numero = values[0].end_numero;
bairro = values[0].end_bairro;
estado = values[0].end_eatado;
cidade = values[0].end_cidade;
cep = values[0].end_cep;
nomeResponsavel = values[0].nome;
},
error:function(e){
console.log(e);
},
complete: function() {
sendRequest(nomeEmpresa,emailEmpresa,telefone,site,rua,numero,bairro,cidade,cep,nomeResponsavel);
}
});
Retrieving information and transforming into json
if(isset($_GET['id']) && $_GET['id']) {
$id = $_GET['id'];
$Partner = new Partner();
$Cliques = new clicks();
date_default_timezone_set('America/Sao_Paulo');
$dataRegistro = date("Y-m-d H:i:s");
$Cliques->setDataRegistro($dataRegistro);
$Cliques->setIdPartner($id);
$Partner->updateContCliques($id);
echo json_encode($Partner->listaParceiro($id));
$Cliques->inserir();
}
Information to send
function sendRequest(nomeEmpresa,emailEmpresa,telefone,site,rua,numero,bairro,cidade,cep,nomeResponsavel) {
var myUrl = encodeURIComponent("http://ecoprintq.com/index.php/partnerApplication/create");
var dados = "User_full_name:"+nomeResponsavel+"&User_institution:"+nomeEmpresa+"&User_email:"+emailEmpresa+"&PartnerApplication_phone:"+telefone+"&PartnerApplication_company_website:"+site+"&PartnerApplication_support_phone:"+telefone+"&PartnerApplication_support_email:"+emailEmpresa;
$.ajax({
url: "webproxy.php?url=" + myUrl,
data:dados,
crossDomain:true,
type: "GET",
timeout: 30000,
dataType: "text", // "xml", "json"
success: function(data) {
window.location.href = "webproxy.php?url=" + myUrl + "&" + dados;
},
error: function(jqXHR, textStatus, ex) {
alert(textStatus + "," + ex + "," + jqXHR.responseText);
}
});
}
Taking the ajax post and sending it to the form
<?php
if (empty($_GET['url']) || preg_match('#^(http|https)://[a-z0-9]#i', $_GET['url']) === 0) {
echo 'URL inválida';
exit;
}
$url = $_GET['url'];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
//pega o POST enviado via Ajax
$post = http_build_query($_POST);
//Envia o $post usando CURL
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($data === false)
{
http_response_code(500);
echo 'Curl error: ' . curl_error($ch);
} elseif ($httpcode !== 200) {
http_response_code($httpcode);
} else {
echo $data;
}
What I have now