I'm calling http_get_request_headers() in a PHP file on a server running PHP 5. However, I'm getting Fatal error: Call to undefined function http_get_request_headers(). Does anyone know what the problem might be? Does this function not come with plain PHP?
No it does not. You need a PECL module for that function to work. But you can use the contents of the $_SERVER variable as stated in this comment on the php site. Alternatively you can use the apache function if this is your web server.
If you're using version >= 2 of pecl_http you'll need to use the namespace syntax for calling the functions. Check out the version 2 documentation here and example here
Basically \http\Env::getRequestHeader()
That function is part of the PECL extension.
Follow the instructions on this page to install it: http://ar.php.net/manual/en/http.install.php
Have you read the Installation and Configuration guide for the HTTP classes/functions?
Related
When making call to sodium_crypto_pwhash_str I get the following in my Apache error log file.
PHP Fatal error: Uncaught Error: Call to undefined function
sodium_crypto_pwhash_str()
My php version, as noted is 7.3.17 running on an Amazon EC2 instance.
My php-info() does not return any relevant libsodium information other than module author info:
Sodium Frank Denis
Given the above author information references a module author am I supposed to enable the sodium module? If the answer is yes is it referenced in the php.ini file? Such as:
extension=sodium
or perhaps:
extension=libsodium
What am I missing here?
Am I not supposed to use the documented function sodium_crypto_pwhash_str?
Am I supposed to use some other method of accessing the desired functionality?
Yes normally it's included in PHP 7.2+ but when you use the AWS EC2 instances this is a bit minimalistic and not everything is included.
https://www.php.net/manual/de/sodium.installation.php
Here you can see that you have to enable it during the compiling with --with-sodium[=DIR]. So you can compile it on your own or you try another distro to get it from your package manager or you use another lib to make it work.
https://forums.aws.amazon.com/thread.jspa?threadID=293187
In PHP (version 7.1), I am attempting to use a MAP as opposed to a two dimensional array to handle implicit data type conversion across different data type groups. However, I am receiving the following run-time error:
Class 'Ds\Map' not found
The error occurs on this line of code:
protected $hive_data_type_group_map = new \Ds\Map();
I have checked online, but there is little documentation on Ds\Map, even on PHP's website (click here). Does anyone know how to fix this?
Data Structures is not a built-in PHP extension.
It needs to be installed before use. The installation instructions are available on php.net.
For windows
Download compiled-dll file "php_ds.dll" from https://pecl.php.net/package/ds. Place it in your dir wamp\bin\php\[your_php_version_folder]\ext and include it in your ".ini" file.
It worked for me.
the easiest way on ubuntu:
pecl install ds
Reference: https://www.php.net/manual/en/ds-deque.allocate.php
After upgrading php to 5.5, the following error occurs:
PHP Fatal error: Call to undefined function bi_to_str() in /var/www/index.php
I know that it's not a coding error, but it could be a missing library. But could an empty value cause that error? Is there an easy way to load that library using apt-get in Debian?
Well with the help I received in the comments, I was able to come up with a solution.
It seems that it's just the function that is missing. I was able to create a file called big_int.php, fill it with the contents found here, and just link to it using require_once in index.php, like this:
require_once('big_int.php');
All is well. Many thanks to Barmar for the helpful tip.
I'm very very new to PHP, but now I have to help my friend to solve a PHP problem.
He has bought a web site based on PHP, after he upload it to the host, found there is a error:
Fatal error: Call to undefined function json_encode() in xxx.php
The code is very simple:
echo json_encode(array(
'result' => true,
));
It send a json to client.
I know json_encode is added after php 5.2, but the PHP version of his host is PHP 5.1.2, so that's the reason why it reports error.
But we don't have the right to upgrade the PHP version of host, so I have to modify the code. How to let it return a json to client without json_encode?
The webpage in client browser will run this javascript code, to get and check that json:
jQuery.ajax({ 'url': '...', ...,
'success':function(json) {
if(json != null && json.result == true) {
// do something
}
}
}
Thanks a lot!
UPDATE
Since I have no rights to upgrade anything or install new libraries to that host, the only thing I can do is change the code. But I nearly know nothing about php, that I don't know how to use 3rd party libraries either. At last, I fix it as this:
In php:
echo '{"result":"true"}';
In javascript:
if(json!=null && json.result=="true") {
// do something
}
First of all: you should strongly consider upgrading, since PHP 5.1.x and 5.2.x are no longer supported. You indicated that you do not have the rights to do so, but if you are a paying customer, that should count for something. PHP 5.2 is deprecated as of the last PHP 5.3.6 release.
A user on PHP.net has provided for a custom function that does the same.
You could rename it to json_decode() and wrap it in a if (!function_exists('json_encode')) statement:
if (!function_exists('json_encode')) {
function json_encode() {
// do stuff
}
}
He has an older PHP version where json_encode is missing. This can be fixed with various 3rd party libraries.
A dated project of mine: http://include-once.org/p/upgradephp/ which provides a drop-in json_encode/json_decode almost identical to PHPs builtin extension (quirky in regards to Unicode).
Then there is https://pear.php.net/package/Services_JSON which even adds JSOL (Object Literals are a superset of JSON) support.
And also http://framework.zend.com/manual/en/zend.json.html which provides a class delivering a pretty thorough reimplementation. (Probably the best-tested version available.)
You can use a third party JSON library, such as the one from the PEAR project (they provide all sorts of useful PHP libraries, of varying quality):
http://pear.php.net/pepr/pepr-proposal-show.php?id=198
I'm sure there are more (I'd try searching Google for PHP JSON libraries).
Why not use a plain PHP json-library which you can include in every setup?
I googled this one here for you.
Read the comments for json_encode at http://www.php.net/manual/en/function.json-encode.php where you also find a comment containing a manual implementation for php < 5.2:
http://www.php.net/manual/de/function.json-encode.php#100835
Further there are also other implementations available via google.
jsonwrapper implements the json_encode function if it is missing, and leaves it alone if it is already present. So it is nicely future-compatible.
i had to install JSON Libs the other day on my server, try the following:
Execute the following commands:
pecl install json
touch /etc/php.d/json.ini
echo "extension=json.so" > /etc/php.d/json.ini
service httpd restart
The first will install the json libraries to your machine, the second line will create the json.ini fiel in the php.d directory and the last line will add the line extension=json.so to the json.ini file.
Hope this helps!
i am trying to create a module that makes a call to the stackexchange API which returns a gzipencoded or a deflated Json response. to decompress it i am using the method http_inflate but i am getting the following error:
Fatal error: Call to undefined function http_inflate()
Is this method dependent on any library or extension?
I am running PHP 5.3.13
http_inflate is not bundled with PHP. It is part of the HTTP library. See this page for instructions on how to install it.
You need to install the HTTP extension, as seen in the link below:
PHP.net: Installing the HTTP plugin
You need to install an extension (pecl_http). See here on php.net for information.