# Ionic login php + token

**URL:** <https://forum.ionicframework.com/t/ionic-login-php-token/62668>\
**Category:** ionic-v1\
**Created:** [September 6, 2016, 9:38am UTC](https://forum.ionicframework.com/t/ionic-login-php-token/62668 "2016-09-06T09:38:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![leugim\_ohlavrac](https://avatars.discourse-cdn.com/v4/letter/l/c6cbf5/32.png) [@leugim\_ohlavrac](https://forum.ionicframework.com/u/leugim_ohlavrac)\
**Post date:** [September 6, 2016, 9:38am UTC](https://forum.ionicframework.com/t/ionic-login-php-token/62668/1 "2016-09-06T09:38:40Z")

</div>

Hi guys,

I’m following [this](https://devdactic.com/user-auth-angularjs-ionic/) tutorial written by Mr Simon about create a login.  
But I’m facing a problem when I want it to check the credentials stored in a database with php.

I modified the services.js to check, but I can figure out what is wrong!  
Please I need your help, i’m stuck on this…

Here is the code I modified in service.js:

```
  var login = function( name, pw) {
       
       $rootScope.rsJSON = [];
       //
       var req = {
     method: 'POST',
     url: 'http://localhost/test/index.php',
     headers: {
       'Content-Type': undefined
     },
     data: { usuario : name , contrasena : pw },
     dataType: "jsonp"
    }

    $http(req)
        .success(function(data, $state) {
       //
    return $q(function(resolve, reject) {
      if (typeof(data.USUARIO) == "undefined") {
        // Make a request and receive your auth token from your server
         reject('Login Failed.');
      } else {
       
          storeUserCredentials(name + '.yourServerToken');
        resolve('Login success.');
      }
    });
        
         })
        .error(function(data) {
            console.log('Error: ' + data);
        });   
        
  };

```

I received the follow errors:

- Error: AuthService.login(…) is undefined;
- Error: Unexpected request: POST [http://localhost/test/index.php](http://localhost/test/index.php)

---

<div class="post-metadata">

**Author:** ![eivanov](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/eivanov/32/101676_2.png) [@eivanov](https://forum.ionicframework.com/u/eivanov)\
**Post date:** [September 6, 2016, 11:45am UTC](https://forum.ionicframework.com/t/ionic-login-php-token/62668/2 "2016-09-06T11:45:04Z")

</div>

Include authService.js in index.html.

---

<div class="post-metadata">

**Author:** ![leugim\_ohlavrac](https://avatars.discourse-cdn.com/v4/letter/l/c6cbf5/32.png) [@leugim\_ohlavrac](https://forum.ionicframework.com/u/leugim_ohlavrac)\
**Post date:** [September 6, 2016, 1:28pm UTC](https://forum.ionicframework.com/t/ionic-login-php-token/62668/3 "2016-09-06T13:28:40Z")

</div>

Hi @eivanov, I don’t understand your point, how can i include AuthService.js in index.html?  
sorry if it is a stupid question, but i’m still learning this

---

<div class="post-metadata">

**Author:** ![sioesi](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@sioesi](https://forum.ionicframework.com/u/sioesi)\
**Post date:** [September 6, 2016, 1:43pm UTC](https://forum.ionicframework.com/t/ionic-login-php-token/62668/4 "2016-09-06T13:43:32Z")

</div>

The error that you receive is not located where they are calling the function is defined.

@leugim_ohlavrac You can add your js file

```
<script src="js/AuthService.js"></script>
```

---

<div class="post-metadata">

**Author:** ![leugim\_ohlavrac](https://avatars.discourse-cdn.com/v4/letter/l/c6cbf5/32.png) [@leugim\_ohlavrac](https://forum.ionicframework.com/u/leugim_ohlavrac)\
**Post date:** [September 6, 2016, 1:47pm UTC](https://forum.ionicframework.com/t/ionic-login-php-token/62668/5 "2016-09-06T13:47:03Z")

</div>

Hi @sioesi, didn’t worked… the error still appearing

---

<div class="post-metadata">

**Author:** ![sioesi](https://avatars.discourse-cdn.com/v4/letter/s/d07c76/32.png) [@sioesi](https://forum.ionicframework.com/u/sioesi)\
**Post date:** [September 6, 2016, 1:49pm UTC](https://forum.ionicframework.com/t/ionic-login-php-token/62668/6 "2016-09-06T13:49:18Z")

</div>

@leugim_ohlavrac You followed the tutorial at the foot dela letter? I’ll check it out!

---

<div class="post-metadata">

**Author:** ![leugim\_ohlavrac](https://avatars.discourse-cdn.com/v4/letter/l/c6cbf5/32.png) [@leugim\_ohlavrac](https://forum.ionicframework.com/u/leugim_ohlavrac)\
**Post date:** [September 6, 2016, 2:19pm UTC](https://forum.ionicframework.com/t/ionic-login-php-token/62668/7 "2016-09-06T14:19:46Z")

</div>

> [@sioesi](#):
>
> foot dela letter

yes, i followed and it works, but i want to change to work with a remote database, called by php… and i’m stuck on this point

---

<div class="post-metadata">

**Author:** ![leugim\_ohlavrac](https://avatars.discourse-cdn.com/v4/letter/l/c6cbf5/32.png) [@leugim\_ohlavrac](https://forum.ionicframework.com/u/leugim_ohlavrac)\
**Post date:** [September 9, 2016, 9:17am UTC](https://forum.ionicframework.com/t/ionic-login-php-token/62668/8 "2016-09-09T09:17:27Z")

</div>

Any tip please? This is important to my project

---

<div class="post-metadata">

**Author:** ![leugim\_ohlavrac](https://avatars.discourse-cdn.com/v4/letter/l/c6cbf5/32.png) [@leugim\_ohlavrac](https://forum.ionicframework.com/u/leugim_ohlavrac)\
**Post date:** [September 14, 2016, 2:29pm UTC](https://forum.ionicframework.com/t/ionic-login-php-token/62668/9 "2016-09-14T14:29:20Z")

</div>

Nobody knows that?  
.
