summaryrefslogtreecommitdiff
path: root/www/posts/atom.xml
diff options
context:
space:
mode:
Diffstat (limited to 'www/posts/atom.xml')
-rw-r--r--www/posts/atom.xml14
1 files changed, 13 insertions, 1 deletions
diff --git a/www/posts/atom.xml b/www/posts/atom.xml
index 751a69c..cabb593 100644
--- a/www/posts/atom.xml
+++ b/www/posts/atom.xml
@@ -4,8 +4,20 @@
<id>https://davidtsadler.com/posts/atom.xml</id>
<link rel="alternate" type="text/html" href="https://davidtsadler.com/posts/index.html"/>
<link rel="self" type="application/atom+xml" href="https://davidtsadler.com/posts/atom.xml"/>
- <updated>2021-06-13T12:00:00Z</updated>
+ <updated>2021-07-08T12:00:00Z</updated>
<entry>
+ <title type="text">HTTP_AUTHORIZATION Missing From Global $_SERVER Variable</title>
+ <id>https://davidtsadler.com/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/index.html</id>
+ <link rel="alternate" type="text/html" href="https://davidtsadler.com/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/index.html"/>
+ <author><name>David T. Sadler.</name></author>
+ <published>2021-07-08T12:00:00Z</published>
+ <updated>2021-07-08T12:00:00Z</updated>
+ <content type="html">&lt;h1&gt;HTTP_AUTHORIZATION Missing From Global $_SERVER Variable&lt;/h1&gt;&lt;blockquote&gt;Thu 8th July 2021 By David T. Sadler.&lt;/blockquote&gt;&lt;p&gt;I came across an issue where I wanted to read the value of the HTTP_AUTHORIZATION key found in PHP's global $_SERVER variable.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;$token = filter_input(INPUT_SERVER, 'HTTP_AUTHORIZATION');&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;However the value of null was been returned even though a Authorization header was passed as part of the HTTP request.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;shell&quot;&gt;$ curl 127.0.0.1:8080/bookmarks/add -i -H &amp;quot;Authorization:Bearer xyz&amp;quot; -d &amp;quot;url=http://example.com/2&amp;quot;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A quick print_r($_SERVER) confirmed that there was indeed no item for the key HTTP_AUTHORIZATION hence why I was getting a null value.&lt;/p&gt;&lt;p&gt;However the value was available with the getallheaders function.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;$token = getallheaders()['Authorization']);&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After a bit of research I found that in some situations Apache may not pass authorization headers to PHP for security reasons. However it is possible to work around this by creating a rewrite rule in the site's .htaccess file to put the authorization header into an environment variable.&lt;/p&gt;&lt;pre&gt;&amp;lt;IfModule mod_rewrite.c&amp;gt;
+ # Handle Authorization Header.
+ RewriteCond %{HTTP:Authorization} .
+ RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
+&amp;lt;/IfModule&amp;gt;&lt;/pre&gt;&lt;p&gt;After adding the above to the .htaccess file the HTTP_AUTHORIZATION key is now been populated with the value of the Authorization header.&lt;/p&gt;&lt;h3&gt;Links&lt;/h3&gt;&lt;a href=&quot;/posts/php&quot;&gt;PHP - Read More Posts.&lt;/a&gt;&lt;p&gt;I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.&lt;/p&gt;&lt;a href=&quot;mailto:david@davidtsadler.com&quot;&gt;Email david@davidtsadler.com&lt;/a&gt;&lt;h3&gt;License&lt;/h3&gt;&lt;a href=&quot;https://creativecommons.org/licenses/by-sa/4.0/&quot;&gt;The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.&lt;/a&gt;&lt;p&gt;Copyright © 2021 David T. Sadler.&lt;/p&gt;&lt;a href=&quot;/&quot;&gt;Return to Homepage.&lt;/a&gt;</content>
+</entry><entry>
<title type="text">Backing Up a Git Repository</title>
<id>https://davidtsadler.com/posts/git/2021-06-13/backing-up-a-git-repository/index.html</id>
<link rel="alternate" type="text/html" href="https://davidtsadler.com/posts/git/2021-06-13/backing-up-a-git-repository/index.html"/>