2
I have three different servers: server A, server B and server C. Where A registers users and stores personal information. I am trying to log in from B and C servers in A using Curl.
I need to return the A values to authenticate user and try to do this with an array and json_encode but I cannot rescue these values to store in php strings on B or C servers.
PHP Curl
<?php
header ('Content-type: text/html; charset=UTF-8');
if(!isset($_SESSION)) session_start();
if(isset($_POST['name'])){
$name = $_POST['name'];
}
if($name == "Fulano"){
$postData = array(
'name' => $name
);
// Initialize cURL
$ch = curl_init();
// Setup options for a cURL transfer
curl_setopt_array(
$ch, array(
CURLOPT_URL => 'http://servidor requisitado/login_ext.php',
CURLOPT_USERAGENT => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)',
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_COOKIEJAR => 'tmp/cookie.txt',
CURLOPT_COOKIEFILE => 'tmp/cookie.txt',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_RETURNTRANSFER, true
));
// Return web page
//return curl_exec($ch);
$server_output = curl_exec ($ch);
curl_close ($ch);
// further processing ....
if($server_output != ''){
$string = json_decode($server_output, true);
//???????????
}
}else{
echo "ERR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
}
PHP login_ext.php
<?php
header ('Content-type: text/html; charset=UTF-8');
if(isset($_POST['name'])){
$name = $_POST['name'];
//Verificação no Banco de dados!
$nameRequest = $fetch['name'];// Ex: Fulano!
$sobrenomeRequest = $fetch['sobrenome'];
if($name == $nameRequest){
$json = array("nome"=>$name, "sobrenome"=>$sobrenomeRequest);
echo json_encode($json);
}
}else{
echo "Err";
}
I tried to make a foreach but without results!
What syntax to retrieve and use these values?
Where do you want to get the values? no "PHP Curl" where you have
$string = json_decode($server_output, true);
below putprint_r($string);
, see which way out.– stderr
The output is a json:{"name":"So-and-so","last name":"Ciclano"}1
– Lauro Moraes
These are the values I cannot assign to a php string...type ($returnName and $returnSobrenome) separately.
– Lauro Moraes