diff options
| -rw-r--r-- | gemini/index.gmi | 1 | ||||
| -rw-r--r-- | gemini/posts/index.gmi | 1 | ||||
| -rw-r--r-- | gemini/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/index.gmi | 51 | ||||
| -rw-r--r-- | gemini/posts/php/index.gmi | 1 | ||||
| -rw-r--r-- | www/index.html | 2 | ||||
| -rw-r--r-- | www/posts/atom.xml | 14 | ||||
| -rw-r--r-- | www/posts/index.html | 2 | ||||
| -rw-r--r-- | www/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/index.html | 29 | ||||
| -rw-r--r-- | www/posts/php/atom.xml | 14 | ||||
| -rw-r--r-- | www/posts/php/index.html | 2 | ||||
| -rw-r--r-- | www/sitemap.xml | 4 |
11 files changed, 116 insertions, 5 deletions
diff --git a/gemini/index.gmi b/gemini/index.gmi index 63d3a88..4cb718d 100644 --- a/gemini/index.gmi +++ b/gemini/index.gmi @@ -4,6 +4,7 @@ Hello and welcome to my little bit of the internet where I occasionally write ab ## Latest Posts +=> /posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/ 2021-07-08 - HTTP_AUTHORIZATION Missing From Global $_SERVER Variable => /posts/git/2021-06-13/backing-up-a-git-repository/ 2021-06-13 - Backing Up a Git Repository => /posts/linux/2021-06-05/xrandr-failed-to-get-size-of-gamma-for-output-default/ 2021-06-05 - Xrandr: Failed to Get Size of Gamma for Output Default => /posts/git/2021-05-29/setting-up-a-self-host-git-server/ 2021-05-29 - Setting up a Self Hosted Git Server diff --git a/gemini/posts/index.gmi b/gemini/posts/index.gmi index 7667661..bcaaa22 100644 --- a/gemini/posts/index.gmi +++ b/gemini/posts/index.gmi @@ -1,5 +1,6 @@ # The Home of David T. Sadler - All Posts +=> /posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/ 2021-07-08 - HTTP_AUTHORIZATION Missing From Global $_SERVER Variable => /posts/git/2021-06-13/backing-up-a-git-repository/ 2021-06-13 - Backing Up a Git Repository => /posts/linux/2021-06-05/xrandr-failed-to-get-size-of-gamma-for-output-default/ 2021-06-05 - Xrandr: Failed to Get Size of Gamma for Output Default => /posts/git/2021-05-29/setting-up-a-self-host-git-server/ 2021-05-29 - Setting up a Self Hosted Git Server diff --git a/gemini/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/index.gmi b/gemini/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/index.gmi new file mode 100644 index 0000000..a6817d9 --- /dev/null +++ b/gemini/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/index.gmi @@ -0,0 +1,51 @@ +# HTTP_AUTHORIZATION Missing From Global $_SERVER Variable + +> Thu 8th July 2021 By David T. Sadler. + +I came across an issue where I wanted to read the value of the HTTP_AUTHORIZATION key found in PHP's global $_SERVER variable. + +```php +$token = filter_input(INPUT_SERVER, 'HTTP_AUTHORIZATION'); +``` + +However the value of null was been returned even though a Authorization header was passed as part of the HTTP request. + +```shell +$ curl 127.0.0.1:8080/bookmarks/add -i -H "Authorization:Bearer xyz" -d "url=http://example.com/2" +``` + +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. + +However the value was available with the getallheaders function. + +```php +$token = getallheaders()['Authorization']); +``` + +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. + +``` +<IfModule mod_rewrite.c> + # Handle Authorization Header. + RewriteCond %{HTTP:Authorization} . + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] +</IfModule> +``` + +After adding the above to the .htaccess file the HTTP_AUTHORIZATION key is now been populated with the value of the Authorization header. + +### Links + +=> /posts/php PHP - Read More Posts. + +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. + +=> mailto:david@davidtsadler.com Email david@davidtsadler.com + +### License + +=> https://creativecommons.org/licenses/by-sa/4.0/ The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. + +Copyright © 2021 David T. Sadler. + +=> / Return to Homepage. diff --git a/gemini/posts/php/index.gmi b/gemini/posts/php/index.gmi index 6a66f56..6ce9e74 100644 --- a/gemini/posts/php/index.gmi +++ b/gemini/posts/php/index.gmi @@ -1,5 +1,6 @@ # The Home of David T. Sadler - All Posts About PHP +=> /posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/ 2021-07-08 - HTTP_AUTHORIZATION Missing From Global $_SERVER Variable => /posts/php/2021-01-18/installing-php-8-for-windows-10/ 2021-01-18 - Installing PHP 8 for Windows 10 ### License diff --git a/www/index.html b/www/index.html index 5c46b20..7cb394b 100644 --- a/www/index.html +++ b/www/index.html @@ -18,7 +18,7 @@ <link href="/posts/php/atom.xml" type="application/atom+xml" rel="alternate" title="The Home of David T. Sadler - All Posts About PHP"/> </head> <body> - <section><h1>The Home of David T. Sadler</h1><p>Hello and welcome to my little bit of the internet where I occasionally write about things that interest me. You might find my posts interesting or you might not and that's okay.</p><h2>Latest Posts</h2><a href="/posts/git/2021-06-13/backing-up-a-git-repository/">2021-06-13 - Backing Up a Git Repository</a><a href="/posts/linux/2021-06-05/xrandr-failed-to-get-size-of-gamma-for-output-default/">2021-06-05 - Xrandr: Failed to Get Size of Gamma for Output Default</a><a href="/posts/git/2021-05-29/setting-up-a-self-host-git-server/">2021-05-29 - Setting up a Self Hosted Git Server</a><a href="/posts/letsencrypt/2021-05-28/pre-and-post-validation-hooks-with-certbot/">2021-05-28 - Pre and Post Validation Hooks with Certbot</a><a href="/posts/letsencrypt/2021-05-27/wildcard-certificates-with-lets-encrypt/">2021-05-27 - Wildcard Certificates with Let's Encrypt</a><a href="/posts/nextcloud/2021-02-15/accessing-nextcloud-with-webdav-on-arch/">2021-02-15 - Accessing Nextcloud With WebDAV on Arch</a><a href="/posts/gemini/2021-02-08/how-to-host-your-own-gemini-site-in-the-cloud/">2021-02-08 - How to Host Your Own Gemini Site in the Cloud</a><a href="/posts/php/2021-01-18/installing-php-8-for-windows-10/">2021-01-18 - Installing PHP 8 for Windows 10</a><a href="/posts/laravel/2020-12-21/installing-laravel-homestead-in-arch-linux/">2020-12-21 - Installing Laravel Homestead in Arch Linux</a><a href="/posts/laravel/2020-12-14/sqlstate-hy000-2002-php-network-getaddresses-getaddrinfo-failed/">2020-12-14 - SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed</a><a href="/posts/arch/2020-09-07/installing-zsh-and-powerlevel10k-on-arch-linux/">2020-09-07 - Installing Zsh and Powerlevel10k on Arch Linux</a><a href="/posts/arch/2020-08-31/enabling-audio-in-arch-linux/">2020-08-31 - Enabling Audio in Arch Linux</a><a href="/posts/arch/2020-08-24/pacman-cheat-sheet-for-ubuntu-users/">2020-08-24 - Pacman Cheat Sheet For Ubuntu Users</a><a href="/posts/arch/2020-08-17/installing-st-dmenu-dwm-in-arch-linux/">2020-08-17 - Installing ST, DMENU and DWM in Arch Linux</a><a href="/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/">2020-07-13 - Sudo: sorry, you must have a tty to run sudo</a><a href="/posts/arch/2020-06-22/granting-sudo-access-to-a-user-in-arch-linux/">2020-06-22 - Granting Sudo Access to a User in Arch Linux</a><a href="/posts/arch/2020-06-15/adding-a-user-in-arch-linux/">2020-06-15 - Adding a User in Arch Linux</a><a href="/posts/netlify/2020-06-08/publishing-jigsaw-posts-with-netlify-build-hooks/">2020-06-08 - Publishing Jigsaw Posts With Netlify Build Hooks</a><a href="/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/">2020-06-01 - Scheduling Posts in Jigsaw</a><a href="/posts/arch/2020-05-25/installing-arch-linux-on-a-thinkpad-x220/">2020-05-25 - Installing Arch Linux on a Thinkpad X220</a><a href="/posts/markdown/2020-03-30/creating-an-ebook-with-markdown/">2020-03-30 - Creating an Ebook With Markdown</a><h2>All Posts</h2><a href="/posts/">Post Archive</a><h2>Tags</h2><a href="/posts/arch/">Arch</a><a href="/posts/gemini/">Gemini</a><a href="/posts/git/">Git</a><a href="/posts/jigsaw/">Jigsaw</a><a href="/posts/laravel/">Laravel</a><a href="/posts/letsencrypt/">Let's Encrypt</a><a href="/posts/linux/">Linux</a><a href="/posts/markdown/">Markdown</a><a href="/posts/netlify/">Netlify</a><a href="/posts/nextcloud/">Nextcloud</a><a href="/posts/php/">PHP</a><h2>Where to Find Me</h2><a href="https://github.com/davidtsadler/">GitHub</a><a href="gemini://davidtsadler.com/">Gemini Site</a><a href="mailto:david@davidtsadler.com">Email david@davidtsadler.com</a><h3>License</h3><a href="https://creativecommons.org/licenses/by-sa/4.0/">The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</a><p>Copyright © 2021 David T. Sadler.</p></section> + <section><h1>The Home of David T. Sadler</h1><p>Hello and welcome to my little bit of the internet where I occasionally write about things that interest me. You might find my posts interesting or you might not and that's okay.</p><h2>Latest Posts</h2><a href="/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/">2021-07-08 - HTTP_AUTHORIZATION Missing From Global $_SERVER Variable</a><a href="/posts/git/2021-06-13/backing-up-a-git-repository/">2021-06-13 - Backing Up a Git Repository</a><a href="/posts/linux/2021-06-05/xrandr-failed-to-get-size-of-gamma-for-output-default/">2021-06-05 - Xrandr: Failed to Get Size of Gamma for Output Default</a><a href="/posts/git/2021-05-29/setting-up-a-self-host-git-server/">2021-05-29 - Setting up a Self Hosted Git Server</a><a href="/posts/letsencrypt/2021-05-28/pre-and-post-validation-hooks-with-certbot/">2021-05-28 - Pre and Post Validation Hooks with Certbot</a><a href="/posts/letsencrypt/2021-05-27/wildcard-certificates-with-lets-encrypt/">2021-05-27 - Wildcard Certificates with Let's Encrypt</a><a href="/posts/nextcloud/2021-02-15/accessing-nextcloud-with-webdav-on-arch/">2021-02-15 - Accessing Nextcloud With WebDAV on Arch</a><a href="/posts/gemini/2021-02-08/how-to-host-your-own-gemini-site-in-the-cloud/">2021-02-08 - How to Host Your Own Gemini Site in the Cloud</a><a href="/posts/php/2021-01-18/installing-php-8-for-windows-10/">2021-01-18 - Installing PHP 8 for Windows 10</a><a href="/posts/laravel/2020-12-21/installing-laravel-homestead-in-arch-linux/">2020-12-21 - Installing Laravel Homestead in Arch Linux</a><a href="/posts/laravel/2020-12-14/sqlstate-hy000-2002-php-network-getaddresses-getaddrinfo-failed/">2020-12-14 - SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed</a><a href="/posts/arch/2020-09-07/installing-zsh-and-powerlevel10k-on-arch-linux/">2020-09-07 - Installing Zsh and Powerlevel10k on Arch Linux</a><a href="/posts/arch/2020-08-31/enabling-audio-in-arch-linux/">2020-08-31 - Enabling Audio in Arch Linux</a><a href="/posts/arch/2020-08-24/pacman-cheat-sheet-for-ubuntu-users/">2020-08-24 - Pacman Cheat Sheet For Ubuntu Users</a><a href="/posts/arch/2020-08-17/installing-st-dmenu-dwm-in-arch-linux/">2020-08-17 - Installing ST, DMENU and DWM in Arch Linux</a><a href="/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/">2020-07-13 - Sudo: sorry, you must have a tty to run sudo</a><a href="/posts/arch/2020-06-22/granting-sudo-access-to-a-user-in-arch-linux/">2020-06-22 - Granting Sudo Access to a User in Arch Linux</a><a href="/posts/arch/2020-06-15/adding-a-user-in-arch-linux/">2020-06-15 - Adding a User in Arch Linux</a><a href="/posts/netlify/2020-06-08/publishing-jigsaw-posts-with-netlify-build-hooks/">2020-06-08 - Publishing Jigsaw Posts With Netlify Build Hooks</a><a href="/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/">2020-06-01 - Scheduling Posts in Jigsaw</a><a href="/posts/arch/2020-05-25/installing-arch-linux-on-a-thinkpad-x220/">2020-05-25 - Installing Arch Linux on a Thinkpad X220</a><a href="/posts/markdown/2020-03-30/creating-an-ebook-with-markdown/">2020-03-30 - Creating an Ebook With Markdown</a><h2>All Posts</h2><a href="/posts/">Post Archive</a><h2>Tags</h2><a href="/posts/arch/">Arch</a><a href="/posts/gemini/">Gemini</a><a href="/posts/git/">Git</a><a href="/posts/jigsaw/">Jigsaw</a><a href="/posts/laravel/">Laravel</a><a href="/posts/letsencrypt/">Let's Encrypt</a><a href="/posts/linux/">Linux</a><a href="/posts/markdown/">Markdown</a><a href="/posts/netlify/">Netlify</a><a href="/posts/nextcloud/">Nextcloud</a><a href="/posts/php/">PHP</a><h2>Where to Find Me</h2><a href="https://github.com/davidtsadler/">GitHub</a><a href="gemini://davidtsadler.com/">Gemini Site</a><a href="mailto:david@davidtsadler.com">Email david@davidtsadler.com</a><h3>License</h3><a href="https://creativecommons.org/licenses/by-sa/4.0/">The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</a><p>Copyright © 2021 David T. Sadler.</p></section> <script defer src="/js/highlight.min.js"></script> <script defer src="/js/site.js"></script> </body> 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"><h1>HTTP_AUTHORIZATION Missing From Global $_SERVER Variable</h1><blockquote>Thu 8th July 2021 By David T. Sadler.</blockquote><p>I came across an issue where I wanted to read the value of the HTTP_AUTHORIZATION key found in PHP's global $_SERVER variable.</p><pre><code class="php">$token = filter_input(INPUT_SERVER, 'HTTP_AUTHORIZATION');</code></pre><p>However the value of null was been returned even though a Authorization header was passed as part of the HTTP request.</p><pre><code class="shell">$ curl 127.0.0.1:8080/bookmarks/add -i -H &quot;Authorization:Bearer xyz&quot; -d &quot;url=http://example.com/2&quot;</code></pre><p>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.</p><p>However the value was available with the getallheaders function.</p><pre><code class="php">$token = getallheaders()['Authorization']);</code></pre><p>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.</p><pre>&lt;IfModule mod_rewrite.c&gt; + # Handle Authorization Header. + RewriteCond %{HTTP:Authorization} . + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] +&lt;/IfModule&gt;</pre><p>After adding the above to the .htaccess file the HTTP_AUTHORIZATION key is now been populated with the value of the Authorization header.</p><h3>Links</h3><a href="/posts/php">PHP - Read More Posts.</a><p>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.</p><a href="mailto:david@davidtsadler.com">Email david@davidtsadler.com</a><h3>License</h3><a href="https://creativecommons.org/licenses/by-sa/4.0/">The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</a><p>Copyright © 2021 David T. Sadler.</p><a href="/">Return to Homepage.</a></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"/> diff --git a/www/posts/index.html b/www/posts/index.html index 0109fec..da1330a 100644 --- a/www/posts/index.html +++ b/www/posts/index.html @@ -18,7 +18,7 @@ <link href="/posts/php/atom.xml" type="application/atom+xml" rel="alternate" title="The Home of David T. Sadler - All Posts About PHP"/> </head> <body> - <section><h1>The Home of David T. Sadler - All Posts</h1><a href="/posts/git/2021-06-13/backing-up-a-git-repository/">2021-06-13 - Backing Up a Git Repository</a><a href="/posts/linux/2021-06-05/xrandr-failed-to-get-size-of-gamma-for-output-default/">2021-06-05 - Xrandr: Failed to Get Size of Gamma for Output Default</a><a href="/posts/git/2021-05-29/setting-up-a-self-host-git-server/">2021-05-29 - Setting up a Self Hosted Git Server</a><a href="/posts/letsencrypt/2021-05-28/pre-and-post-validation-hooks-with-certbot/">2021-05-28 - Pre and Post Validation Hooks with Certbot</a><a href="/posts/letsencrypt/2021-05-27/wildcard-certificates-with-lets-encrypt/">2021-05-27 - Wildcard Certificates with Let's Encrypt</a><a href="/posts/nextcloud/2021-02-15/accessing-nextcloud-with-webdav-on-arch/">2021-02-15 - Accessing Nextcloud With WebDAV on Arch</a><a href="/posts/gemini/2021-02-08/how-to-host-your-own-gemini-site-in-the-cloud/">2021-02-08 - How to Host Your Own Gemini Site in the Cloud</a><a href="/posts/php/2021-01-18/installing-php-8-for-windows-10/">2021-01-18 - Installing PHP 8 for Windows 10</a><a href="/posts/laravel/2020-12-21/installing-laravel-homestead-in-arch-linux/">2020-12-21 - Installing Laravel Homestead in Arch Linux</a><a href="/posts/laravel/2020-12-14/sqlstate-hy000-2002-php-network-getaddresses-getaddrinfo-failed/">2020-12-14 - SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed</a><a href="/posts/arch/2020-09-07/installing-zsh-and-powerlevel10k-on-arch-linux/">2020-09-07 - Installing Zsh and Powerlevel10k on Arch Linux</a><a href="/posts/arch/2020-08-31/enabling-audio-in-arch-linux/">2020-08-31 - Enabling Audio in Arch Linux</a><a href="/posts/arch/2020-08-24/pacman-cheat-sheet-for-ubuntu-users/">2020-08-24 - Pacman Cheat Sheet For Ubuntu Users</a><a href="/posts/arch/2020-08-17/installing-st-dmenu-dwm-in-arch-linux/">2020-08-17 - Installing ST, DMENU and DWM in Arch Linux</a><a href="/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/">2020-07-13 - Sudo: sorry, you must have a tty to run sudo</a><a href="/posts/arch/2020-06-22/granting-sudo-access-to-a-user-in-arch-linux/">2020-06-22 - Granting Sudo Access to a User in Arch Linux</a><a href="/posts/arch/2020-06-15/adding-a-user-in-arch-linux/">2020-06-15 - Adding a User in Arch Linux</a><a href="/posts/netlify/2020-06-08/publishing-jigsaw-posts-with-netlify-build-hooks/">2020-06-08 - Publishing Jigsaw Posts With Netlify Build Hooks</a><a href="/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/">2020-06-01 - Scheduling Posts in Jigsaw</a><a href="/posts/arch/2020-05-25/installing-arch-linux-on-a-thinkpad-x220/">2020-05-25 - Installing Arch Linux on a Thinkpad X220</a><a href="/posts/markdown/2020-03-30/creating-an-ebook-with-markdown/">2020-03-30 - Creating an Ebook With Markdown</a><h3>License</h3><a href="https://creativecommons.org/licenses/by-sa/4.0/">The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</a><p>Copyright © 2021 David T. Sadler.</p><a href="/">Return to Homepage.</a></section> + <section><h1>The Home of David T. Sadler - All Posts</h1><a href="/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/">2021-07-08 - HTTP_AUTHORIZATION Missing From Global $_SERVER Variable</a><a href="/posts/git/2021-06-13/backing-up-a-git-repository/">2021-06-13 - Backing Up a Git Repository</a><a href="/posts/linux/2021-06-05/xrandr-failed-to-get-size-of-gamma-for-output-default/">2021-06-05 - Xrandr: Failed to Get Size of Gamma for Output Default</a><a href="/posts/git/2021-05-29/setting-up-a-self-host-git-server/">2021-05-29 - Setting up a Self Hosted Git Server</a><a href="/posts/letsencrypt/2021-05-28/pre-and-post-validation-hooks-with-certbot/">2021-05-28 - Pre and Post Validation Hooks with Certbot</a><a href="/posts/letsencrypt/2021-05-27/wildcard-certificates-with-lets-encrypt/">2021-05-27 - Wildcard Certificates with Let's Encrypt</a><a href="/posts/nextcloud/2021-02-15/accessing-nextcloud-with-webdav-on-arch/">2021-02-15 - Accessing Nextcloud With WebDAV on Arch</a><a href="/posts/gemini/2021-02-08/how-to-host-your-own-gemini-site-in-the-cloud/">2021-02-08 - How to Host Your Own Gemini Site in the Cloud</a><a href="/posts/php/2021-01-18/installing-php-8-for-windows-10/">2021-01-18 - Installing PHP 8 for Windows 10</a><a href="/posts/laravel/2020-12-21/installing-laravel-homestead-in-arch-linux/">2020-12-21 - Installing Laravel Homestead in Arch Linux</a><a href="/posts/laravel/2020-12-14/sqlstate-hy000-2002-php-network-getaddresses-getaddrinfo-failed/">2020-12-14 - SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed</a><a href="/posts/arch/2020-09-07/installing-zsh-and-powerlevel10k-on-arch-linux/">2020-09-07 - Installing Zsh and Powerlevel10k on Arch Linux</a><a href="/posts/arch/2020-08-31/enabling-audio-in-arch-linux/">2020-08-31 - Enabling Audio in Arch Linux</a><a href="/posts/arch/2020-08-24/pacman-cheat-sheet-for-ubuntu-users/">2020-08-24 - Pacman Cheat Sheet For Ubuntu Users</a><a href="/posts/arch/2020-08-17/installing-st-dmenu-dwm-in-arch-linux/">2020-08-17 - Installing ST, DMENU and DWM in Arch Linux</a><a href="/posts/linux/2020-07-13/sudo-sorry-you-must-have-a-tty-to-run-sudo/">2020-07-13 - Sudo: sorry, you must have a tty to run sudo</a><a href="/posts/arch/2020-06-22/granting-sudo-access-to-a-user-in-arch-linux/">2020-06-22 - Granting Sudo Access to a User in Arch Linux</a><a href="/posts/arch/2020-06-15/adding-a-user-in-arch-linux/">2020-06-15 - Adding a User in Arch Linux</a><a href="/posts/netlify/2020-06-08/publishing-jigsaw-posts-with-netlify-build-hooks/">2020-06-08 - Publishing Jigsaw Posts With Netlify Build Hooks</a><a href="/posts/jigsaw/2020-06-01/scheduling-posts-in-jigsaw/">2020-06-01 - Scheduling Posts in Jigsaw</a><a href="/posts/arch/2020-05-25/installing-arch-linux-on-a-thinkpad-x220/">2020-05-25 - Installing Arch Linux on a Thinkpad X220</a><a href="/posts/markdown/2020-03-30/creating-an-ebook-with-markdown/">2020-03-30 - Creating an Ebook With Markdown</a><h3>License</h3><a href="https://creativecommons.org/licenses/by-sa/4.0/">The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</a><p>Copyright © 2021 David T. Sadler.</p><a href="/">Return to Homepage.</a></section> <script defer src="/js/highlight.min.js"></script> <script defer src="/js/site.js"></script> </body> diff --git a/www/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/index.html b/www/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/index.html new file mode 100644 index 0000000..7bf96dc --- /dev/null +++ b/www/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/index.html @@ -0,0 +1,29 @@ +<!doctype html> +<html lang="en"> + <head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <title>HTTP_AUTHORIZATION Missing From Global $_SERVER Variable</title> + <link rel="shortcut icon" href="/images/favicon.png"> + <link rel="stylesheet" href="/css/site.css"> + <link href="/posts/atom.xml" type="application/atom+xml" rel="alternate" title="The Home of David T. Sadler - All Posts"/> + <link href="/posts/arch/atom.xml" type="application/atom+xml" rel="alternate" title="The Home of David T. Sadler - All Posts About Arch"/> + <link href="/posts/gemini/atom.xml" type="application/atom+xml" rel="alternate" title="The Home of David T. Sadler - All Posts About Gemini"/> + <link href="/posts/jigsaw/atom.xml" type="application/atom+xml" rel="alternate" title="The Home of David T. Sadler - All Posts About Jigsaw"/> + <link href="/posts/laravel/atom.xml" type="application/atom+xml" rel="alternate" title="The Home of David T. Sadler - All Posts About Laravel"/> + <link href="/posts/linux/atom.xml" type="application/atom+xml" rel="alternate" title="The Home of David T. Sadler - All Posts About Linux"/> + <link href="/posts/markdown/atom.xml" type="application/atom+xml" rel="alternate" title="The Home of David T. Sadler - All Posts About Markdown"/> + <link href="/posts/netlify/atom.xml" type="application/atom+xml" rel="alternate" title="The Home of David T. Sadler - All Posts About Netlify"/> + <link href="/posts/nextcloud/atom.xml" type="application/atom+xml" rel="alternate" title="The Home of David T. Sadler - All Posts About Nextcloud"/> + <link href="/posts/php/atom.xml" type="application/atom+xml" rel="alternate" title="The Home of David T. Sadler - All Posts About PHP"/> + </head> + <body> + <section><h1>HTTP_AUTHORIZATION Missing From Global $_SERVER Variable</h1><blockquote>Thu 8th July 2021 By David T. Sadler.</blockquote><p>I came across an issue where I wanted to read the value of the HTTP_AUTHORIZATION key found in PHP's global $_SERVER variable.</p><pre><code class="php">$token = filter_input(INPUT_SERVER, 'HTTP_AUTHORIZATION');</code></pre><p>However the value of null was been returned even though a Authorization header was passed as part of the HTTP request.</p><pre><code class="shell">$ curl 127.0.0.1:8080/bookmarks/add -i -H "Authorization:Bearer xyz" -d "url=http://example.com/2"</code></pre><p>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.</p><p>However the value was available with the getallheaders function.</p><pre><code class="php">$token = getallheaders()['Authorization']);</code></pre><p>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.</p><pre><IfModule mod_rewrite.c> + # Handle Authorization Header. + RewriteCond %{HTTP:Authorization} . + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] +</IfModule></pre><p>After adding the above to the .htaccess file the HTTP_AUTHORIZATION key is now been populated with the value of the Authorization header.</p><h3>Links</h3><a href="/posts/php">PHP - Read More Posts.</a><p>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.</p><a href="mailto:david@davidtsadler.com">Email david@davidtsadler.com</a><h3>License</h3><a href="https://creativecommons.org/licenses/by-sa/4.0/">The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</a><p>Copyright © 2021 David T. Sadler.</p><a href="/">Return to Homepage.</a></section> + <script defer src="/js/highlight.min.js"></script> + <script defer src="/js/site.js"></script> + </body> +</html> diff --git a/www/posts/php/atom.xml b/www/posts/php/atom.xml index bac171d..278a6bd 100644 --- a/www/posts/php/atom.xml +++ b/www/posts/php/atom.xml @@ -4,8 +4,20 @@ <id>https://davidtsadler.com/posts/php/atom.xml</id> <link rel="alternate" type="text/html" href="https://davidtsadler.com/posts/php/index.html"/> <link rel="self" type="application/atom+xml" href="https://davidtsadler.com/posts/php/atom.xml"/> - <updated>2021-01-18T12: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"><h1>HTTP_AUTHORIZATION Missing From Global $_SERVER Variable</h1><blockquote>Thu 8th July 2021 By David T. Sadler.</blockquote><p>I came across an issue where I wanted to read the value of the HTTP_AUTHORIZATION key found in PHP's global $_SERVER variable.</p><pre><code class="php">$token = filter_input(INPUT_SERVER, 'HTTP_AUTHORIZATION');</code></pre><p>However the value of null was been returned even though a Authorization header was passed as part of the HTTP request.</p><pre><code class="shell">$ curl 127.0.0.1:8080/bookmarks/add -i -H &quot;Authorization:Bearer xyz&quot; -d &quot;url=http://example.com/2&quot;</code></pre><p>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.</p><p>However the value was available with the getallheaders function.</p><pre><code class="php">$token = getallheaders()['Authorization']);</code></pre><p>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.</p><pre>&lt;IfModule mod_rewrite.c&gt; + # Handle Authorization Header. + RewriteCond %{HTTP:Authorization} . + RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] +&lt;/IfModule&gt;</pre><p>After adding the above to the .htaccess file the HTTP_AUTHORIZATION key is now been populated with the value of the Authorization header.</p><h3>Links</h3><a href="/posts/php">PHP - Read More Posts.</a><p>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.</p><a href="mailto:david@davidtsadler.com">Email david@davidtsadler.com</a><h3>License</h3><a href="https://creativecommons.org/licenses/by-sa/4.0/">The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</a><p>Copyright © 2021 David T. Sadler.</p><a href="/">Return to Homepage.</a></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/index.html</id> <link rel="alternate" type="text/html" href="https://davidtsadler.com/posts/php/2021-01-18/installing-php-8-for-windows-10/index.html"/> diff --git a/www/posts/php/index.html b/www/posts/php/index.html index a274e1d..4b9c00d 100644 --- a/www/posts/php/index.html +++ b/www/posts/php/index.html @@ -18,7 +18,7 @@ <link href="/posts/php/atom.xml" type="application/atom+xml" rel="alternate" title="The Home of David T. Sadler - All Posts About PHP"/> </head> <body> - <section><h1>The Home of David T. Sadler - All Posts About PHP</h1><a href="/posts/php/2021-01-18/installing-php-8-for-windows-10/">2021-01-18 - Installing PHP 8 for Windows 10</a><h3>License</h3><a href="https://creativecommons.org/licenses/by-sa/4.0/">The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</a><p>Copyright © 2021 David T. Sadler.</p><a href="/">Return to Homepage.</a></section> + <section><h1>The Home of David T. Sadler - All Posts About PHP</h1><a href="/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/">2021-07-08 - HTTP_AUTHORIZATION Missing From Global $_SERVER Variable</a><a href="/posts/php/2021-01-18/installing-php-8-for-windows-10/">2021-01-18 - Installing PHP 8 for Windows 10</a><h3>License</h3><a href="https://creativecommons.org/licenses/by-sa/4.0/">The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</a><p>Copyright © 2021 David T. Sadler.</p><a href="/">Return to Homepage.</a></section> <script defer src="/js/highlight.min.js"></script> <script defer src="/js/site.js"></script> </body> diff --git a/www/sitemap.xml b/www/sitemap.xml index b83b2c5..43888a6 100644 --- a/www/sitemap.xml +++ b/www/sitemap.xml @@ -1,6 +1,10 @@ <?xml version="1.0" encoding="utf-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"> <url> + <loc>https://davidtsadler.com/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/index.html</loc> + <lastmod>2021-07-08T12:00:00Z</lastmod> + <changefreq>never</changefreq> +</url><url> <loc>https://davidtsadler.com/posts/git/2021-06-13/backing-up-a-git-repository/index.html</loc> <lastmod>2021-06-13T12:00:00Z</lastmod> <changefreq>never</changefreq> |
