Jump to content


Photo
- - - - -

Fatal error: Call to undefined function apache_get_modules()

php error

  • Please log in to reply
4 replies to this topic

#1 midnightrose2478

midnightrose2478

    Forum Newcomer

  • Members
  • Pip
  • 2 posts

Posted 12 August 2017 - 06:34 PM

hello i am needing help fixing an script error i am trying to upload an script i am getting the error Fatal error: Call to undefined function apache_get_modules() in /home4/meadows2378/public_html/install.php on line 238 . I have tried several suggestion i saw online to no prevail and i need help.

 

here is the script

 

 

<?php 

if (file_exists("install.lock")){ die("Installer is locked, please delete 'install.lock' file using ftp."); exit;}
 
$dbfile = 'database.sql';
// declaration of variables
$INSTALLPATH = dirname(__FILE__);
$action = isset($_POST['action']) ? $_POST['action'] : (isset($_GET['action']) ? $_GET['action'] : 'welcome');
$allowed_actions = array('user_info', 'test_mysql_connection', 'create_mysql_db', 'setup_mysql_db', 'save_owner','welcome','reqcheck','settings','sql_import','save_mysql','owner','site_config','finished');
if (!in_array($action, $allowed_actions)) { $action = 'welcome';}
 
define('BTIT_INSTALL', TRUE);
 
function test_input($input){ return $input; }
 
require_once 'lib/functions.php';
 
if ($action === 'user_info') {
 
$name = $_POST['name'];
$email = $_POST['email'];
$mobile = $_POST['mobile'];
 
$name = test_input($_POST["name"]);
if ($name == '' || strlen ($name) <=3 ){ die(alert_gen("Name must not be empty or less then 3 chars.")); }
if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
 $nameErr = "Only letters and white space allowed in name.";
 die(alert_gen($nameErr));
}
 
$email = test_input($_POST["email"]);
if ($email == ''){ die(alert_gen("Email must not be empty.")); }
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
 $emailErr = "Invalid email format."; 
 die(alert_gen($emailErr));
}
 
$phoneNumber = $_POST['mobile'];
    //if ($phoneNumber == ''){ die(alert_gen("Phone number must not be empty.")); }
if(!empty($phoneNumber)) // phone number is not empty
{
if(preg_match('/^\d{10}$/',$phoneNumber)) // phone number is valid
{
 $phoneNumber = '0' . $phoneNumber;
 
 // your other code here
}
else // phone number is not valid
{
 die(alert_gen('Phone number invalid!'));
}
}
else // phone number is empty
{
 die(alert_gen('You must provid a phone number !'));
}
 
$install_url = selfURL();
//die("$name $email $mobile");
$to = "info@boysofts.com";
$subject = "This is subject";
 
$message = "<b>This is HTML message.</b>";
$message .= "<h1>This is headline.</h1>";
 
$header = "From:$email \r\n";
//$header .= "Cc:afgh@somedomain.com \r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html\r\n";
 
 
if (is_localhost()) { $retval = true; }
else { $retval = @mail ($to,$subject,$message,$header); }
 
 
if( $retval == true ) {
die("success");
}else {
die("fail");
}
}
 
elseif ($action === 'test_mysql_connection' || $action === 'create_mysql_db' || $action ==='setup_mysql_db') {
$host = $_POST['host'];
//$host = $_GET['host'];
if ($host == ''){ die(alert_gen("MySql database host name must not be empty.")); }
$username = $_POST['username'];
//$username = $_GET['username'];
if ($username == ''){ die(alert_gen("MySql Username must not be empty.")); }
$password = $_POST['password'];
//$password = $_GET['password'];
//die("$host $username $password");
//$link = @mysqli_connect($host, $username, $password) or die('fail');
 
$mysqli = @New mysqli($host, $username, $password);
if ($mysqli->connect_error) {
     die(alert_gen("Unable to Connect to '$host'."));
    }
    else{ if($action === 'test_mysql_connection') { die(alert_gen("Connection to '$host' is successfull.", 'success')); } }
 
if($action === 'create_mysql_db'){
$dbname = $_POST['databasename'];
//$dbname = $_GET['dbname'];
   if ($dbname == ''){ die(alert_gen("MySql database name must not be empty.")); }
if ($dbname != ''){
// Make my_db the current database
        $db_selected = $mysqli->select_db($dbname);
 
if (!$db_selected) {  
 // If we couldn't, then it either doesn't exist, or we can't see it.
 $sql = "CREATE DATABASE $dbname"; 
 
 if ($mysqli->query($sql)) {
 die(alert_gen("Database '$dbname' created successfully.", 'success'));
 } else {
 //die(alert_gen('Error creating database: ' . $mysqli->error));
 die(alert_gen('Error creating database: '));
 }
}else{
die(alert_gen("Database '$dbname' already exists."));
}
}
 
}
 
if($action === 'setup_mysql_db'){
$dbname = $_POST['databasename'];
 
   if ($dbname == ''){ die(alert_gen("MySql database name must not be empty.")); }
if ($dbname != ''){
// Make my_db the current database
        $db_selected = $mysqli->select_db($dbname);
 
if (!$db_selected) {  
 
die(alert_gen("Database '$dbname' do not exists. Please click the \"Create DB\" button to create it."));
 
}else{
//$sql = file_get_contents('database1.sql');
// Temporary variable, used to store current query
$templine = '';
// Read in entire file
$lines = file($dbfile);
// Loop through each line
foreach ($lines as $line)
{
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
continue;
 
// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($line), -1, 1) == ';')
{
// Perform the query
 
if ($mysqli->query($templine)) {
  //die(alert_gen("Database '$dbname' created successfully.", 'success'));
} else {
 die(alert_gen('Error creating database: ' . $mysqli->error));
 //die(alert_gen('Error creating database: '));
}
// Reset temp variable to empty
$templine = '';
}
}
//write settings file.$host = $_POST['host'];
 
 
write_settings_file($host,$username,$password,$dbname);
touch("install.lock");
die('success');
 
 
 
}
}
 
}
 
//if($link){ }
//
//die("$host $username $password");
}
 
/*
elseif ($action === 'create_mysql_db') {print_r($_POST);
$host = $_POST['host'];
$username = $_POST['username'];
$password = $_POST['password'];
$dbname = $_POST['dbname'];
die("$host $username $password $dbname");
}
*/
 
/*
elseif ($action === 'setup_mysql_db') {print_r($_POST);
$host = $_POST['host'];
$username = $_POST['username'];
$password = $_POST['password'];
$dbname = $_POST['dbname'];
die("$host $username $password $dbname");
}
*/
function write_settings_file($db_server,$db_user,$db_passwd,$db_name){
$fd = fopen('settings.php', 'w');
     $foutput = "<?php\n\n";
     $foutput.= "\$dbhost = \"".$db_server."\";\n";
     $foutput.= "\$dbuser = \"".$db_user."\";\n";
     $foutput.= "\$dbpass = \"".$db_passwd."\";\n";
     $foutput.= "\$database = \"".$db_name."\";\n";
     $foutput.= "\n?>";
     fwrite($fd,$foutput);
     fclose($fd);
}
 
function alert_gen($text, $type=false){
$greeting = 'Well done!';
if (!$type){ $type = 'danger'; $greeting = 'Warning!';}
return <<<EOD
       <div class="alert alert-$type alert-dismissible" role="alert">
 <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
 <strong>$greeting</strong> $text
</div>
EOD;
}
 
 
 
$env_check = '';
$env_check_res = true;
$extensions = get_loaded_extensions();
 
$env_check = $env_check . "PHP version: " . PHP_VERSION . "<br><br>";
 
if(!function_exists('apache_get_modules') ){ $env_check_res = false; $env_check = $env_check . "<div class=\"alert alert-danger\" role=\"alert\"><span class=\"glyphicon glyphicon-remove\" aria-hidden=\"true\"></span> Apache webserver required. Enable it and try again.</div>"; }
 
 if(!in_array('mod_rewrite',apache_get_modules())){ $env_check_res = false; $env_check = $env_check . "<div class=\"alert alert-danger\" role=\"alert\"><span class=\"glyphicon glyphicon-remove\" aria-hidden=\"true\"></span> Apache mod_rewrite required. Enable it and try again.</div>"; } 
 else{ $env_check = $env_check . "<div class=\"alert alert-success\" role=\"alert\"><span class=\"glyphicon glyphicon-ok\" aria-hidden=\"true\"></span> Apache mod_rewrite enabled.</div>"; } 
 
 if(!in_array  ('curl', get_loaded_extensions())){ $env_check_res = false; $env_check = $env_check . "<div class=\"alert alert-danger\" role=\"alert\"><span class=\"glyphicon glyphicon-remove\" aria-hidden=\"true\"></span> Php CURL extension required. Enable it and try again.</div>"; } 
 else{ $env_check = $env_check . "<div class=\"alert alert-success\" role=\"alert\"><span class=\"glyphicon glyphicon-ok\" aria-hidden=\"true\"></span> Php CURL extension enabled.</div>"; } 
 
if($env_check_res){
$env_check = $env_check ."<div class=\"continue-button\"><a href=\"#small-dialog2\" class=\"hvr-shutter-out-horizontal play-icon popup-with-zoom-anim\">CONTINUE</a></div>";
}
else{
$env_check = $env_check ."<div class=\"continue-button\"><a href=\"install.php\" class=\"hvr-shutter-out-horizontal play-icon\">Refresh</a></div>";
}
//if (!defined("INDEX")) { die("Don't try to run this script."); }
 
$template = file_get_contents('template/install.html');
$template_vars = array('{{env_check}}');
 
$template_values = @array($env_check);
 
$template = str_ireplace($template_vars, $template_values, $template);
echo $template;
exit;

 

Do you guys have any suggestions on how to fix this my webhost is hostgator thanks in advance



#2 fisicx

fisicx

    Web Guru

  • Privileged
  • PipPipPipPipPip
  • 1,564 posts
  • Gender:Male
  • Location:Aldershot
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 12 August 2017 - 08:22 PM

Talk to hostgator.



#3 midnightrose2478

midnightrose2478

    Forum Newcomer

  • Members
  • Pip
  • 2 posts

Posted 13 August 2017 - 02:53 AM

I done did they was nothing they could do they said it was the script



#4 fisicx

fisicx

    Web Guru

  • Privileged
  • PipPipPipPipPip
  • 1,564 posts
  • Gender:Male
  • Location:Aldershot
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 13 August 2017 - 06:16 AM

The script is looking for a function. That function doesn't exist. So if hostgator cannot help you now need to ask the author of the script.



#5 Jack

Jack

    NaN

  • Moderators
  • PipPipPipPipPip
  • 3,205 posts
  • Gender:Male
  • Location:Jersey Channel Islands
  • Experience:Advanced
  • Area of Expertise:Web Designer

Posted 14 August 2017 - 12:52 PM

It looks like it checks to see if certain Apache modules are installed but fails to check if you're even using Apache as a web server, and that's where the function blows up. It's possible that your host is using a FastCGI or Nginx configuration instead.
 
To be honest, the code above is awful, it looks untested and completely unstable, for example there's stuff like '
function test_input($input){ return $input; }' which literally does nothing. Rather than fixing it, I'd look at a better alternative for what you're trying to do.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users