简体   繁体   中英

PHP files with 'cmt' extension (?)

This might sound a bit silly. I have to update a website with a new interface, and although I received the old code I am lost. (As far as I know, I received the complete website, phpPgAdmin included)

Most of the files are .cmt but I'm pretty sure it's PHP, index.cmt for instance is

<?
include_once('redirected.php');
exit();
function get_lang_from_ip() {
    $client_ip = $_SERVER['REMOTE_ADDR'];
    $client_hostname = gethostbyaddr($client_ip);

    if ($client_ip != $client_hostname) {
        $dom_arr = split('\.',$client_hostname);
        $lang_id = ($dom_arr[sizeof($dom_arr)-1] == 'hu') ? 'hu' : 'en';
    } else {
        $lang_id = 'hu';
    }
    return $lang_id;
}

function set_target() {
    $valid_lang_arr = array('hu', 'en');
    if (isset($_GET['lang_id']) && in_array($_GET['lang_id'], $valid_lang_arr)) {
        $lang_id = $_GET['lang_id'];
    } elseif (isset($_COOKIE['lang_id']) && in_array($_COOKIE['lang_id'], $valid_lang_arr)) {
        $lang_id = $_COOKIE['lang_id'];
    } else {
        $lang_id = 'hu'; //get_lang_from_ip();
    }
    setcookie('lang_id', $lang_id, time()+3600*24*365, '/');
    return $lang_id;
}

header('Connection: close');
header('Location: /'.set_target().'/');
?>

The .php files however don't begin with the <? short opening tag, but with <?php instead. And most importantly, the .cmt files are not parsed, if I navigate to the index.cmt I see the code in the browser, and thus I can't even put the old layout back together.

Any help is appreciated.

You can make a .htaccess file, and include the following:

AddType application/x-httpd-php .cmt

That should allow PHP to be executed on .cmt file extensions.

Please note that this fix can only be used on Apache web servers or others that support .htaccess .


Although, if possible, I'd recommend that you change all .cmt file extensions to their appropriate counter part, .php .

While @Josh Foskett has a valid answer, I think an actual solution would be to go through your files and rename the .cmt extensions to .php for scalability and to avoid confusion down the road.

Consider "phasing out" the legacy extensions by bringing them up to the current extension standard. Make this a project, not a quick fix, and I think you'll be much happier with your code base.

You need to configure your server to parse .cmt files as PHP.

Also, both <? and <?php are valid opening tags for PHP, though the short version might be turned off in PHP settings (usually define in php.ini somewhere in the filesystem).

Enable short_open_tag in php.ini.

This will make sure, that php is actually executed, if it's included from an other file. It still won't execute, .cmt files directly, but if you have main .php entry files, that's exactly the behaviour you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM