0
Beginner in programming if anyone can help me.
<?php
ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, X-Requested-With");
if(!empty($_POST['nome']) && !empty($_POST['email']) && !empty($_POST['telefone'] && !empty($_POST['formId'])){
// echo "Variaveis enviadas";
$data = $_POST['nome'];
$data = $_POST['email'];
$data = $_POST['telefone'];
$data['telefone_key'] = substr($data['telefone'], 3);
if(strlen($data['telefone_key']) == 10){
$newTel = substr($data['telefone_key'], 0, 2) . "9" . substr($data['telefone_key'], 2);
$data['telefone_key'] = $new;
}
$data['telefone_criptografado'] = criptografar($data['telefone']);
$formId = $_POST['formId'];
pushMauticForm($data,$formId);
} else {
echo "Variaveis não enviadas";
}
function criptografar(telefone){
$tel = telefone.toString();
$remover = array("(", ")", "+", " ", "-");
str_replace($remover, "", $tel);
$cifra = [ "0", "1", "1", "2", "2", "2", "3", "3", "3", "3"];
$telCripto = "";
for ($i = 0; $i < $tel.length; $i++) {
$telCripto += $cifra[parseInt($tel[i])];
}
return $telCripto;
}
function pushMauticForm($data, $formId, $ip = null){
$ip = "191.252.129.245";
$dados = array("dados" => $data, "formId" => $formId);
//print_r($dados);
$content = http_build_query($dados);
//print_r($content);
$context = stream_context_create(array(
'http' => array(
'header' => "Content-Type: application/x-www-form-urlencoded\r\n",
"Content-Length:" .strlen ($content),
'method' => 'POST',
'content' => $content,
)
));
//echo "<br>";
//print_r($context);
$result = file_get_contents('https://teste.com.br/', null, $context);
}
?>
This is the code I have to receive the information that my webhook sends, I tested it is normally sending the information, but the url that contains this my code is appearing error 500 and I can’t identify which error I’ve searched and can’t find, I put the code to php to show me the errors, but it is not showing. I’ll put up the prints. You are returning error 500 Print test Webhook: https://prnt.sc/17o7kzh Print reply screen URL: https://prnt.sc/17o7ua7
You are setting the functions after calling them?
– Woss
Opa @Woss, not actually the error is in the function encrypt, the phone variables, had not put the $ to declare them.
– Roger