Fatal error: Call to undefined function checkdnsrr() - php

My application checks MX-records on the registration page. It works fine on my local development machine (Windows 7 with WAMP Server) and on my hosting account (Linux server). Recently I deployed the app on another hosting account and I got the following error when I tried to register an user:
Fatal error: Call to undefined function checkdnsrr() in
D:\home\memorytreephoto.com\wwwroot\MyCMS\controls\register\validate_email.php
on line 27
My code is below:
<?php
// ------------------------------------------------------------
// VALIDATE E-MAIL
// ------------------------------------------------------------
if (!filter_var($txbEmail, FILTER_VALIDATE_EMAIL)) {
$emailNotValid = $email_error;
$emailvalidate_error = 1;
}
if (filter_var($txbEmail, FILTER_VALIDATE_EMAIL)) {
if (domain_exists($txbEmail)) {
$emailvalidate_error = 0;
} else {
$emailNotValid = $emailmx_error;
$emailvalidate_error = 1;
}
}
// Check if MX-records are present
function domain_exists($emailtocheck, $record = 'MX') {
list($user, $domain) = preg_split('/#/', $emailtocheck);
return checkdnsrr($domain, $record);
}
?>
Does someone know how to fix this?

A look in the manual shows that this function exists on Windows only since PHP 5.3.0. You'd have to upgrade to that PHP version to make the function work.
Alternatively, there is a PEAR Class that provides the functionality to PHP versions < 5.3.0

This function is only available in PHP 5.3.0 or higher if you're running Windows.

Maybe you need to remove the checkdnsrr from disable_functions at php.ini file or maybe your hosting provider do not have this fuction in the php.ini. Check this also, another ideas about PHP version.

Related

php if behaves different in windows and linux

Recently I came to know that there is a slight difference in code behavior due to host platform.
$result = Data::my_custom_function($data, 'id');
//comment : my_custom_function($array, $id) --- it will return either false or string based on business logic
if($result)
{
return $result;
}
else
{
return false;
}
Above code runs fine with Windows if STRING is returned by function, but the same is not happening on CentOS server where the project is hosted.
It goes to else part even if there is string in $result variable.
I had to change the code to follow to have it run on both:
if(!empty($result) && is_string($result) && strlen($result) > 0)
{
return $result;
}
else
{
return false;
}
Why it happened I have no idea. Maybe because Windows is bit soft on strict policy like file name you can write on upper/lower case it goes without issue but in Linux kernel filename must be exactly in lower/upper case as it is on the file system.
Please help.
System Info:
Both server and Local machine are equipped with PHP-7.4.x
Localhost is Windows 10
Server is Cent OS 7.x

Unusual error in code igniter system file when deployed to a VPS server

I recently finished building my site using code igniter on WAMP local server and tested it on a shared hosting server (from Namecheap). Then I got VPS hosting plan (from iPage) and uploaded the files and did the necessary configs. However, I got this error when I tried accessing the site:
An uncaught Exception was encountered
Type: Error
Message: Call to undefined function ctype_digit()
Filename: /home/eastngco/public_html/system/core/Security.php
Line Number: 600
Problem is, the suspect file, Security.php, is a code igniter system file which I never messed with (everything I wrote was within the application folder). Below is a code snippet around the line in Security.php causing the error:
/**
* Get random bytes
*
* #param int $length Output length
* #return string
*/
public function get_random_bytes($length)
{
if (empty($length) OR ! ctype_digit((string) $length))
{
return FALSE;
}
if (function_exists('random_bytes'))
{
try
{
// The cast is required to avoid TypeError
return random_bytes((int) $length);
}
catch (Exception $e)
{
// If random_bytes() can't do the job, we can't either ...
// There's no point in using fallbacks.
log_message('error', $e->getMessage());
return FALSE;
}
}
// Unfortunately, none of the following PRNGs is guaranteed to exist ...
if (defined('MCRYPT_DEV_URANDOM') && ($output = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)) !== FALSE)
{
return $output;
}
if (is_readable('/dev/urandom') && ($fp = fopen('/dev/urandom', 'rb')) !== FALSE)
{
// Try not to waste entropy ...
is_php('5.4') && stream_set_chunk_size($fp, $length);
$output = fread($fp, $length);
fclose($fp);
if ($output !== FALSE)
{
return $output;
}
}
if (function_exists('openssl_random_pseudo_bytes'))
{
return openssl_random_pseudo_bytes($length);
}
return FALSE;
}
I have no idea what random bytes or ctype_digit() means!
I did some digging on the web to see if a similar problem (and its solution) would pop, but nothing did. I need help fixing this please.
If it means anything, the PHP version that comes with my hosting plan is version 7, and I have SSL.
Ipage has a support page to enable the ctype extension, please read this article, using code igniter and PHP: 7.4.10, I receive this error message: Call to undefined function ctype_digit().
Enabling this extension in Ipage the problem was solved in my case.
Article:
https://www.ipage.com/help/article/how-to-enable-ctype-so-extensions-in-php-ini
Looks like your provider might have explicitly disabled those types of functions. It should be enabled by default. Try contacting your provider for some support on enabling these, or reinstalling PHP without that flag turned off.
http://us2.php.net/manual/en/ctype.installation.php
Additionally, you could try and inspect a phpinfo() page to confirm whether ctypes are enabled or not. It seems weird that they would turn it off, so this would help figure out if this is part of the issue.

Anonymous functions not working in PHP 5.5.x

So, here is a small code snippet from my project
if (!empty($user['IndustryUser'])) {
$user['IndustryUser'] = array_filter($user['IndustryUser'], function ($ku) {
$k = !empty($ku['Industry']['name']) ? trim($ku['Industry']['name']): '';
return $k != '';
});
$userIndustries = array();
foreach ($user['IndustryUser'] as $ku) {
$userIndustries[] = $ku;
}
$user['IndustryUser'] = $userIndustries;
}
This code is present inside a Model named User.php. And also there is a shell script named FetchIndustriesShell.php inside app/console/command, which makes use of this Model.
When I run this script from the command line, as cake FetchIndustries, I get the following error
Parse error: syntax error, unexpected T_FUNCTION in D:\wamp\www\industry-svn\
app\Model\User.php on line 203
where Line 203, is where the anonymous function is defined(line 2 from code snippet).
What i tried is
1) Run phpinfo() inside bootstrap.php to verify the php version. It shows PHP 5.5.12 (attached is the screenshot).
2) I installed xampp,to verify if my wampp installtion/php libraries had problem. But I still got the same error.
3) Also referred https://github.com/cakephp/debug_kit/issues/134. But that did not help either.
CakePHP Version used is: 2.5.1
Project currently running on: wampp (local)

Modx Evo with PHP 5.4 and eval

Got a bit of an issue with Modx and latest version of PHP.
It's a very old version of Modx (don't ask - I have exactly the same thoughts, wasn't in my control). The site is working fine on PHP 5.2.
The problem is the web host is upgrading to PHP 5.4 - as a result the site breaks completely. The one issue I can't get a solution for is the use of eval within manager/includes/document.parser.class.inc.php under "evalSnippet()" function where it calls depreciated eval() function.
I've looked at possibliity of upgrading Modx to latest which is 1.0.9, however this still uses eval() -> even though it explicity states this version supports PHP 5.4. Below is the code:
function evalSnippet($snippet, $params) {
$etomite= $modx= & $this;
$modx->event->params= & $params; // store params inside event object
if (is_array($params)) {
extract($params, EXTR_SKIP);
}
ob_start();
$snip= eval ($snippet);
$msg= ob_get_contents();
ob_end_clean();
if ((0<$this->config['error_reporting']) && isset($php_errormsg))
{
$error_info = error_get_last();
if($error_info['type']===2048 || $error_info['type']===8192) $error_type = 2;
else $error_type = 3;
if(1<$this->config['error_reporting'] || 2<$error_type)
{
extract($error_info);
if($msg===false) $msg = 'ob_get_contents() error';
$result = $this->messageQuit('PHP Parse Error', '', true, $type, $file, 'Snippet', $text, $line, $msg);
if ($this->isBackend())
{
$this->event->alert("An error occurred while loading. Please see the event log for more information<p>{$msg}{$snip}</p>");
}
}
}
unset ($modx->event->params);
return $msg . $snip;
}
Is there away around this? Has anyone managed to get Modx Evo working with PHP 5.4?
Continued from comments on original post...
session_is_registered() is deprecated as of PHP 5.3. You'll need to check through your snippets and find out which one is using this function, then replace it with isset($_SESSION['name_of_variable']).
Quickest way to find it would be to run a %LIKE% search in phpMyAdmin for session_is_registered on the modx_site_snippets table

How to use php dl function for librets.dll for rets client

I dont want to jump into everything as I'm about to leave work, I would just like suggestions or things to change. I have a centos linux server and this is the code that's giving me the error and i'm not sure whats wrong since I downloaded it like this and it wont work.
if (!extension_loaded('librets')) {
if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
if (!dl('php_librets.dll')) return;
} else {
// PHP_SHLIB_SUFFIX gives 'dylib' on MacOS X but modules are 'so'.
if (PHP_SHLIB_SUFFIX === 'dylib') {
if (!dl('librets.so')) return;
} else {
if (!dl('librets.'.PHP_SHLIB_SUFFIX)) return;
}
}
}
I get the following error:
Fatal error: Call to undefined function dl() in /home/removed/public_html/test/rets2/librets.php on line 22
I'm not sure whats wrong..
Anyone?
dl is not a good solution for loading libraries under certain conditions, which is why the function has been removed from several of the SAPI-s (Server APIs - the connection between PHP and the server running PHP). You'll either have to add it to php.ini or load it through whatever means your server has available for that. If you're on shared hosting, the hoster may also have disabled dl() for security reasons.

Categories