summaryrefslogtreecommitdiff
path: root/www/posts/php/atom.xml
diff options
context:
space:
mode:
Diffstat (limited to 'www/posts/php/atom.xml')
-rw-r--r--www/posts/php/atom.xml6
1 files changed, 3 insertions, 3 deletions
diff --git a/www/posts/php/atom.xml b/www/posts/php/atom.xml
index 9f64dc4..6970ec0 100644
--- a/www/posts/php/atom.xml
+++ b/www/posts/php/atom.xml
@@ -12,11 +12,11 @@
<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;
+ <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&amp;#039;s global $_SERVER variable.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;php&quot;&gt;$token = filter_input(INPUT_SERVER, &amp;#039;HTTP_AUTHORIZATION&amp;#039;);&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()[&amp;#039;Authorization&amp;#039;]);&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&amp;#039;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>
+&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&amp;#039;t have comments as I don&amp;#039;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">Installing PHP 8 for Windows 10</title>
<id>https://davidtsadler.com/posts/php/2021-01-18/installing-php-8-for-windows-10/</id>
@@ -28,6 +28,6 @@
PHP 8.0.1 (cli) (built: Jan 5 2021 23:43:33) ( NTS Visual C++ 2019 x64 )
Copyright (c) The PHP Group
-Zend Engine v4.0.1, Copyright (c) Zend Technologies&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Links&lt;/h3&gt;&lt;a href=&quot;https://windows.php.net/&quot;&gt;PHP For Windows.&lt;/a&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>
+Zend Engine v4.0.1, Copyright (c) Zend Technologies&lt;/code&gt;&lt;/pre&gt;&lt;h3&gt;Links&lt;/h3&gt;&lt;a href=&quot;https://windows.php.net/&quot;&gt;PHP For Windows.&lt;/a&gt;&lt;a href=&quot;/posts/php&quot;&gt;PHP - Read More Posts.&lt;/a&gt;&lt;p&gt;I don&amp;#039;t have comments as I don&amp;#039;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>
</feed> \ No newline at end of file