php


Header can not set - SlimFramework


I have the same problem again.
Old post here
I have a angular app and SlimFramework for api connect.
Local it works fine but when i publish to my Website come the error that my Header no set.
But the info on the API testing tool says it's allowed from * IP.
Can someone help me?
Here a valid token: Basic TyOSZcfBwMC6DR9kbAWeMnPmhF4ohZu2n9LccQEyt6uXNt8PTT
Thx
$app = new \Slim\App(["settings" => $config]);
$container = $app->getContainer();
$app->options('/{routes:.+}', function ($request, $response, $args) {
return $response;
});
$app->add(function ($req, $res, $next) {
$response = $next($req, $res);
return $response
->withHeader('Access-Control-Allow-Origin', '*')
->withHeader('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Accept, Origin, Authorization')
->withHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, DELETE, PUT');
});
$container['logger'] = function($c) {
$logger = new \Monolog\Logger('my_logger');
$file_handler = new \Monolog\Handler\StreamHandler("../../logs/app.log");
$logger->pushHandler($file_handler);
return $logger;
};
$app->get('/token', function ($request, $response){
$db = new DbOperation();
if (!$request->hasHeader('Authorization')) {
return $response->withJson([
"success"=> false,
"message" => "Header not set.",
"textcode"=> "MSG2"
], 401);
}
$token = $request->getHeader('Authorization');
if($db->checkToken($token[0])){
$user = $db->userInfo($token[0]);
if($db->checkActivate($user['auth_user'])){
if($db->checkExpired($user['auth_user'])){
return $response->withJson([
"success"=> false,
"message" => "The validity of the login has expired. If you have any questions, please contact the administrator..",
"textcode"=> "MSG6"
], 401);
} else {
return $response->withJson(["success"=> true], 200);
}
} else {
return $response->withJson([
"success"=> false,
"message" => "This account has not yet been activated.",
"textcode"=> "MSG8"
], 401);
}
} else {
return $response->withJson([
"success"=> false,
"message"=>'Invalid token',
"textcode"=> "MSG1"
], 403);
}
});
Your basic auth credentials do not decode into anything meaningful. PHP tends to silently ignore Authorization headers which it thinks are malformed. Try with something like Basic dGVzdDp0ZXN0 which decodes into test:test.
Workaround for this has however been added to Slim starting from version 3.5.0. Upgrading your Slim installation might also help.

Related Links

CSS #import not working with PHP
Wordpress: Display all pages
Insert values from function php in database mysql
WooCommerce coupon code per line item
Datetime ISO 8601
Website design using html and php(no javascript/jquery/ajax) [closed]
Getting no response on Zoho API CRM
Get summed value from specific rows
how to use $_FILES[] with slim
Set Background Image from Custom Meta in WordPress
Email Sending error mail() function
Read cookie from parent directory
Google ping failing - cURL
CURL invoking API with SSL
Something goes wrong with filter, not saving data
Yii: Force authenticate

Categories

HOME
jboss
office365
protocol-buffers
class
jms
concurrency
devexpress
mousemove
kivy
braintree
magento-2.0
bing-search
mirc
lvm
azure-data-lake
azure-mobile-services
impala
fedora
telegraf
azure-logic-apps
amazon-emr
tiff
outlook-restapi
spring-jpa
user-defined-types
l20n
maven-plugin
xsl-fo
spam
raml
bluemix-mobile-services
eclipse-emf
pdf.js
jstree
web-config-transform
sap-lumira
django-import-export
bonita
fusion
epplus
caesar-cipher
markov-chains
transform
djcelery
installanywhere
unification
best-buy-api
python-jira
icepdf
apache-toree
oracle-bmcs
vesta
kitura
viewmodel
cordova-ios
solr-query-syntax
gtk#
mongodb-aggregation
wikimapia
prefetch
annotatorjs
controllers
ipywidgets
msbuild-4.0
psd
cortana
phpquery
srv-record
netdatacontractserializer
knife
wlanapi
explain
ipod
scala-macros
prism-4
kognitio-wx2
createfile
lifetime
n-tier-architecture
window-resize
mfmessagecomposeview
sqlbindparameter
webaii
pre
ember-table
flv
dibs
spiral
cmath
django-filebrowser
handshake
gprof
multiscaleimage
workflow-manager-1.x
wcf-callbacks
wiktionary
background-repeat
asio
delphi-prism
office-automation
kohana-auth
mediacontroller
digiflow
formal-semantics
html-components
error-detection

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App