我正在尝试将json响应集成到电子商务模板的前端UI。我正在集成json响应以登录UI。到目前为止我已经完成了从登录的json响应获得价值。当我尝试使用电子邮件值abc@gmail.com和密码123456登录时,它会重定向到主页,因为在javascript中给予,但即使我尝试使用不正确的未注册密码,它也会重定向到带有错误值的主页。
当用户使用上述用户名和密码登录时,它会重定向到主页并欢迎用户名显示在主页上,并在其附近显示注销标签。
Json回应
{
"error": false,
"data": {
"userId": "65",
"name": "Name",
"email": "abc@gmail.com",
"password": null,
"gender": "m",
"phone": "1234567890",
"dob": "1499797800000",
"bloodGroup": "A+",
"startDate": "1484159400000",
"fb_id": "",
"google_id": "",
"api_key": "3f009d72559f51e7e454b16e5d0687a1",
"otp": null,
"createdOn": "1497764349267",
"updatedOn": "1500979353326"
},
"message": "Login Successful.."
}
PHP
<?php include("header.php");?>
<div role="main" class="main">
<section class="form-section">
<div class="container">
<h1 class="h2 heading-primary font-weight-normal mb-md mt-lg">Login or Create an Account</h1>
<div class="featured-box featured-box-primary featured-box-flat featured-box-text-left mt-md">
<div class="box-content">
<!-- <form action="#"> -->
<div class="row">
<div class="col-sm-6">
<div class="form-content">
<h3 class="heading-text-color font-weight-normal">New Customers</h3>
<p>By creating an account with our store, you will be able to move through the checkout process faster, store multiple shipping addresses, view and track your orders in your account and more.</p>
</div>
<div class="form-action clearfix">
<a href="demo-shop-5-register.php" class="btn btn-primary">Create an Account</a>
</div>
</div>
<div class="col-sm-6">
<?php $json_string = '{"error":false,"data":{"userId":"65","name":"Name","email":"abc@gmail.com","password":null,"gender":"m","phone":"1234567890","dob":"1499797800000","bloodGroup":"A+","startDate":"1484159400000","fb_id":"","google_id":"","api_key":"3f009d72559f51e7e454b16e5d0687a1","otp":null,"picturePath":"\/var\/www\/html\/JacchaBacchaDevelopers\/v1\/uploads\/1499924350_pp.png","createdOn":"1497764349267","updatedOn":"1500979353326"},"message":"Login Successful.."}';
$array = json_decode($json_string, true);
//$message = "wrong answer";
if(isset($_POST['login']))
{
$user = $array['data']['email'];
$pass = $array['data']['password'];
if(is_array($array)) {
$_SESSION["userId"] = $array['data']['userId'];
}
if($user===$array['data']['email'] && $pass===$array['data']['password'])
{
$_SESSION["userId"] = $array['data']['userId'];
echo '<script language="javascript">';
echo "window.location.href = 'demo-shop-5.php'";
echo '</script>';
}
else
{
echo '<script language="javascript">';
echo 'alert("invalid email or password")';
echo '</script>';
}
}?>
-->
<form method="POST" action="">
<div class="error-message"><?php if(isset($message)) { echo $message; } ?></div>
<div class="form-content">
<h3 class="heading-text-color font-weight-normal">Registered Customers</h3>
<p>If you have an account with us, please log in.</p>
<div class="form-group">
<label class="font-weight-normal">Email Address <span class="required">*</span></label>
<input type="email" class="form-control" required name="email" value="<?php echo $email;?>">
</div>
<div class="form-group">
<label class="font-weight-normal">Password <span class="required">*</span></label>
<input type="password" class="form-control" required name="password" value="<?php echo $password;?>">
</div>
<p class="required">* Required Fields</p>
</div>
<div class="form-action clearfix">
<a href="#" class="pull-left">Forgot Your Password?</a>
<input type="submit" class="btn btn-primary" name="login" value="Submit">
</div>
</form>
</div>
</div>
<!-- </form> -->
</div>
</div>
</div>
</section>
</div>
<?php include("footer.php"); ?>
webservice的基本网址
http://139.59.36.134/JacchaBacchaDevelopers/v1/index.php/login
答案 0 :(得分:1)
您必须在电子邮件中存储$ _POST值并传递。 chaange以下行
$user = $array['data']['email'];
$pass = $array['data']['password'];
到
$user = $_POST['email'];
$pass = $_POST['password'];