How to pass a form variable to another page via JSON? I had create two php file with file naming page_login.php and login.php. However when running login_post.php, the $json value unable pass to login.php
page_login.php:
$email = test@gmail.com;
$password = 123;
$json = array('email' => $email, 'password' => hash("sha256",$password));
$json = json_encode($json);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://localhost/login.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
login.php:
$json=json_decode($_REQUEST["json"],true);
print $json;
Try this
page_login.php
$email = "test@gmail.com";
$password = "123";
$json = array('email' => $email, 'password' => hash("sha256",$password));
$json = json_encode($json);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://localhost/login.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(array("json" => $json)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($ch);
curl_close ($ch);
echo $server_output;
login.php
$json=json_decode($_REQUEST["json"],true);
foreach ($json as $key => $value) {
echo $key . ": " . $value;
echo "<BR>";
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.