Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header("Access-Control-Allow-Origin: *");
- header("Content-Type: application/json; charset=UTF-8");
- error_reporting(0);
- if($_SERVER['REQUEST_METHOD']=="POST")
- {
- $username= $_POST['username'];
- $password=$_POST['password'];
- if(!$username && !$password)
- {
- echo json_encode(array("error"=>true,"message"=>"Need username and password for login"));
- }
- else
- {
- $dbcon=new mysqli("localhost","root","","php");
- $sql="SELECT `user_id`, `username`, `fullname`, `password` FROM `user` WHERE username='user' and password='123456';";
- $result=$dbcon->query($sql);
- if($result->num_rows>0)
- {
- $row=$result->fetch_assoc();
- $user=array(
- 'user_id'=>$row['user_id'],
- 'username'=>$row['username'],
- 'fullname'=>$row['fullname']
- );
- echo json_encode(array("error"=>false,"message"=>"Login Success","data"=>$user));
- }
- else
- {
- echo json_encode(array("error"=>true,"message"=>"Wrong username or password"));
- }
- }
- }
- else
- {
- echo json_encode(array("error"=>true,"message"=>"Only POST Method allows"));
- }
Add Comment
Please, Sign In to add comment