Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to authenticate to a Yii API (Yii Version 1.1.15) using an ionic / angular app, and can't get headers within the PHP page.

The angular code is:

 $http({
        headers: {'X_ASCCPE_USERNAME': username,'X_ASCCPE_PASSWORD': password},
        url: 'http://example.com/index.php/',            
        params: {r: 'api/list',model: 'users',callback:'JSON_CALLBACK'}
    })

and the PHP code is:

    $username = $_SERVER['HTTP_X_'.self::APPLICATION_ID.'_USERNAME'];
    $password = $_SERVER['HTTP_X_'.self::APPLICATION_ID.'_PASSWORD'];

but the username and password are not set in $_SERVER['HTTP_X_ASCCPE_USERNAME'] and
$_SERVER['HTTP_X_ASCCPE_PASSWORD'].

The only place I see these is HTTP_ACCESS_CONTROL_REQUEST_HEADERS==>accept, x_asccpe_password, x_asccpe_username

How do I pass these from angular ($http) to PHP / Yii ?

share|improve this question
    
This looks to be an issue with Angular: github.com/angular/angular.js/issues/1004 –  lilbiscuit yesterday

1 Answer 1

You are prepending HTTP_ to the header. But it is not needed.

Change your php code to:

$username = $_SERVER['X_'.self::APPLICATION_ID.'_USERNAME'];
$password = $_SERVER['X_'.self::APPLICATION_ID.'_PASSWORD'];
share|improve this answer
    
@Krill That's not correct and causes a server error. You don't include HTTP_ when you send, but you need it to parse on receiving end. –  lilbiscuit yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.