CHARAFI Saad CHARAFI Saad - 1 year ago 61
PHP Question

Retrieve an object (PHP&ANGULARJS)

I want to retrieve an object sent from an Angular function to a PHP program.
Here is my view:

<ion-content padding="true">
<div class="card">
<div class="item item-divider text-center">
<div class="item item-text-wrap text-center">
<div class="list">
<label class="item item-input">
<input type="text" placeholder="Nom d'utilisateur" ng-model="user.username">

<label class="item item-input">
<input type="password" placeholder="mot de passe" ng-model="user.password">


<div class="item item-divider text-center">
<a href="" class="button button-positive button-small" ng-click="logIn(user)">
<i class="ionicons ion-android-share"></i>
Identifiez moi, vite !
<a href="" class="button button-energized button-small">
<i class="ionicons ion-android-mail"></i>
Mot de passe perdu !
<button class="button button-large button-full button-positive">
je n'ai pas de compte

Here is controller :

'use strict';

.controller('homepageIndex',function ($scope) {
.controller('homepageLogin',function ($scope , userProvider) {

$scope.logIn = function (user) {


Here is my userProvider.js

'use strict';

app.factory('userProvider', function ($rootScope , $http) {

function logIn(user) {
var url='';

.success(function (response) {



return {
logIn: logIn

In my file
I want to retrieve this object user which contains username and password:

$username =$_POST['username'];
$password =$_POST['password'];

This method doesn't work i want to know how to retrieve username and password in my rest.php
Thank u for ur help.

Answer Source

@Mohit Tanwani

$request = json_decode(file_get_contents('php://input'));

You can put this at the start of your PHP script. $request will then be an stdClass object with the data as properties.

$username = $request->username;
$password = $request->password;

Alternatively, if you prefer to work with it as assoc array, use:

$request = json_decode(file_get_contents('php://input'), TRUE);

and access data like:

$username = $request['username'];
$password = $request['password'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download