check version of php

    0

    2

    jvit
    JVIT PHP

    The first if statement checks the PHP_VERSION_ID value and determines whether or not it is below 70400. If it is, the http_response_code() function will return a 500 error. The second if statement tests if the PHP_VERSION_ID value is greater than or equal to 80200. If it is, the http_response_code() function will return a 500 error.

    Shortcut: system.requireVersion

    // Show warning if < PHP 7.4
    if (PHP_VERSION_ID < 70400) {
      http_response_code(500);
      echo 'This version requires at least PHP 7.4<br/>';
      echo 'You are currently running ' . PHP_VERSION . '. Please update your PHP version.';
      exit(1);
    }
    
    // Show warning if >= PHP 8.2 is not compatible with >= PHP 8.2 for now
    if (PHP_VERSION_ID >= 80200) {
      http_response_code(500);
      echo 'This version is not compatible with PHP>=8.2.<br/>';
      echo 'You are currently running ' . PHP_VERSION . '.';
      exit(1);
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.