此页面是通过result.php
全局变量获取$_SESSION
的数据,并通过Guzzle将后发请求发送到API的时间:
<?php require 'vendor/autoload.php';
$json = $_COOKIE["Token"] ;
$obj2 = json_decode($json, true );
$token = $obj2["token"];
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Psr7\Request;
$client = new Client([
'headers' => [ 'Content-Type' => 'application/json',
'Token' => $token]
]);
$response = $client->post('http://localhost:91/Religious',
['body' => json_encode(
[
"religious" => "admin",
"religiousLang2" => "123456",
"religiousLang3" => "123456"
]
)]
);
echo '<pre>' . var_export($response->getStatusCode(), true).'</pre>';
echo '<pre>' . var_export($response->getBody()->getContents(), true) . '</pre>';
?>
result.php
此页面是用户单击按钮(用户界面页面)时的页面。所以我想知道当用户点击按钮时如何将此页面中的数据发送到API?
<?php
session_start();
include('connect-db.php');
$result = mysql_query("SELECT * FROM patientvaccinedetail")
$specific = [];
while($row = mysql_fetch_array( $result ,MYSQL_ASSOC)) {
echo "<tr>";
echo '<td width="100px">' . $row['id'] . '</td>';
echo '<td width="200px">' . $row['patientid'] . '</td>';
echo '<td width="200px">' . $row['vaccineid'] . '</td>';
//**********Convert the array into json*******************
$specific = ["religious" => $row["id"],
"religiousLang2" => $row["patientid"],
"religiousLang3" => $row["vaccineid"]];
}
$result = json_encode($specific,JSON_UNESCAPED_UNICODE);
$_SESSION['hi'] = "$result";
echo "</tr>";
echo "</table>";
?>
<a href="guzzle.php"><button name="send" type="submit" class="btn btn-primary">Send sms alert</button></a>