Is there an alternative to apache_request_headers for displaying HTTP headers

I am currently developing an application in IGB (In-Game-Browser) for online MMO. For third-party development, the browser sends HTTP headers in game information such as "Locations", "Product Identifier", "Object Type Identifiers", etc.

This is a small script that I practice with. This script works on my local server and, like everyone else posted on this issue, it does not work on my web server. I came to the conclusion that this is due to the fact that Apache is not installed as a module. I spoke with my hosting provider. They said that they can’t tell me anything but to find an alternative to apache_request_headers. I have looked at all the previously posted editions of this topic on this site, and I cannot understand how it all fits together. How to use the examples here to achieve my final result. Like this [question]: Calling the undefined function apache_request_headers ()

My code is:

<?php $headers = apache_request_headers(); foreach ($headers as $header => $value) { echo "$header: $value <br />\n"; } ?> 

My mistake:

 Fatal error: Call to undefined function apache_request_headers() in /home/ncgotggb/public_html/ezalternatives.com/index.php on line 2 

I studied when I travel this year, and he was self-taught and fast paced, so I'm still new to these concepts. At the moment, I have no choice, I am very interested and must finish it. When displaying your answer It would be very appreciated if you demonstrated your solution in full.

+6
source share
2 answers

It looks like Apache is running on your local server, and your remote server is not, because this function only works with Apache (if only the server does not work with PHP 5.4.0, then it also works in FastCGI.

On the PHP manual page for this function, one of the commentators included a replacement function, which will be declared only if the built-in does not exist. I did not test this, but I saw the same function as in other places.

 if( !function_exists('apache_request_headers') ) { function apache_request_headers() { $arh = array(); $rx_http = '/\AHTTP_/'; foreach($_SERVER as $key => $val) { if( preg_match($rx_http, $key) ) { $arh_key = preg_replace($rx_http, '', $key); $rx_matches = array(); // do some nasty string manipulations to restore the original letter case // this should work in most cases $rx_matches = explode('_', $arh_key); if( count($rx_matches) > 0 and strlen($arh_key) > 2 ) { foreach($rx_matches as $ak_key => $ak_val) { $rx_matches[$ak_key] = ucfirst($ak_val); } $arh_key = implode('-', $rx_matches); } $arh[$arh_key] = $val; } } return( $arh ); } } 
+8
source

I found that my site in ISP Config was set up so that PHP was "Fast-CGI" - this changed it perfectly to "MOD-PHP".

0
source

Source: https://habr.com/ru/post/950941/


All Articles