blob: 9f64dc4de242c086af26d2c1a7bd7dbea698a613 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">The Home of David T. Sadler - All Posts About PHP</title>
<id>https://davidtsadler.com/posts/php/atom.xml</id>
<link rel="alternate" type="text/html" href="https://davidtsadler.com/posts/php/"/>
<link rel="self" type="application/atom+xml" href="https://davidtsadler.com/posts/php/atom.xml"/>
<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/</id>
<link rel="alternate" type="text/html" href="https://davidtsadler.com/posts/php/2021-07-08/http-authorization-missing-from-global-server-variable/"/>
<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/</id>
<link rel="alternate" type="text/html" href="https://davidtsadler.com/posts/php/2021-01-18/installing-php-8-for-windows-10/"/>
<author><name>David T. Sadler.</name></author>
<published>2021-01-18T12:00:00Z</published>
<updated>2021-01-18T12:00:00Z</updated>
<content type="html"><h1>Installing PHP 8 for Windows 10</h1><blockquote>Mon 18th January 2021 By David T. Sadler.</blockquote><h2>Getting Started</h2><p>The PHP For Windows site provides pre-built Windows binaries for you to download. Which version you download depends upon two things.</p><p>1. Is your system a 64 or 32 bit machine.</p><p>2. Are you planning to use IIS or Apache as the web server.</p><p>For 64 bit systems the x64 file should be downloaded. If you plan to use IIS then get the Non Thread Safe (NTS) version otherwise use the Thread Safe (TS) version.</p><p>The PHP 8 binaries require to have the Visual C++ Redistributable for Visual Studio 2015-2019 be installed as well.</p><h2>Download and Installation</h2><p>1. Download the Visual C++ Redistributable for Visual Studio 2015-2019 executable and install it.</p><p>2. Download the appropriate PHP 8 Zip archive for your Windows system. </p><p>3. Extract the Zip archive into a folder called php in your user folder. This should result in a folder at C:\Users\[username]\php.</p><h2>Configuring Windows</h2><p>In order to run the PHP executable from the command line the path to where the Zip archive was extracted to needs to be added to the Windows Path environment variable. </p><p>1. Right click on the start menu and select System.</p><p>2. Type Control Panel into the search field and select the Control Panel option when it appears.</p><p>3. Click System and Security and then the System option.</p><p>4. Click Advanced system settings from the left side menu to bring up a dialog box.</p><p>5. Select the Advanced tab and then click Environment Variables.</p><p>6. Select the Path option from the User variables list and click Edit.</p><p>7. Click New and enter the path to where you extracted the Zip archive. This should be C:\Users\[username]\php. You can also click Browse instead and navigate to the folder.</p><p>8. Click OK to close the Edit environment variable dialog.</p><p>9. Click OK again to close the Environment Variables dialog.</p><p>10. Click OK for a third time to close the System Properties dialog.</p><h2>Checking Installation</h2><p>Open up either PowerShell or the Command Prompt and enter php -v to verify that PHP was installed correctly. You should see output similar to that shown below.</p><pre><code class="shell">C:\Users\dev&gt;php -v
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</code></pre><h3>Links</h3><a href="https://windows.php.net/">PHP For Windows.</a><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>
</feed>
|