What I am trying to do is add a password,username headers to this http get request. Then have the .php page allow the function if the username and password are correct. I have seen a lot of answers concerning headers for basic authorization and posting data. What I am trying to do is add some basic security to this http get request.
data.ts
getData() {
let headers = new Headers({ 'Content-Type':'*/*' });
headers.append('Authorization', 'Basic' + (loginname + ':' + password) );
this.http.get('https:data.php', { headers: headers }, {})
.map(res => res.json())
.subscribe(data => {
console.log(data.data);
},
err => {
this.connectionAlert();
});
}
data.php
<?php
$login = ‘loginname’; // move to lib config
$pass = ‘password’; // move to lib config
if (!isset($_SERVER['PHP_AUTH_PW']!= $pass || $_SERVER['PHP_AUTH_USER'] != $login)) {
header('WWW-Authenticate: Basic realm="My Site"');
header('HTTP/1.0 401 Unauthorized');
echo 'User not allowed';
exit;
} else {
echo "<p>Sucess</p>";
}
?>
My error is
Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
The answers I have found online do not seem to fix the problem.