Jump to main content
University Computer Centre
PHP
University Computer Centre 

PHP: Hypertext Preprocessor

PHP is a powerful script language for web authors. You write special instructions in the HTML text that the web server interprets before the page is delivered to the browser.

The central web servers www.tu-chemnitz.de and www-user.tu-chemnitz.de are configured almost identically regarding PHP:

www.tu-chemnitz.de PHP-Commands in the central web space PHP 8 – Configuration
www-user.tu-chemnitz.de PHP-Commands in the user's web space PHP 8 – Configuration

Introduction, Documentation

Files with PHP commends must have the extensions .html (recommended) or .php, then the PHP code they contain will also be interpreted.

Files with the extension .phps are not interpreted, but the source text is displayed directly in the browser. (So be careful with code that contains business logic or internal comments!) .phps access is not allowed by default (Require all denied), it has to be entitled explicitly.

This is how it looks in the web browser – PHP statements are executed.

This is how it is programmed
– PHP statements in the file

You can see that the PHP instructions are separated from the HTML text by the tags <?php …  ?>. It also becomes clear that PHP features important elements of a programming language – variables, terms, statements, control elements, classes. For a description, please refer to the following documents:

Be sure to read our notes on safe programming with PHP.

Notes

PHP Error Messages (For Development/Troubleshooting)

Display errors on the web page (only during development)

  • in file .htaccess: php_flag display_errors on
  • Please switch off again after the development phase.

Write errors to a file

  • in file .htaccess:
    # write PHP error in file
    php_value log_errors on
    # file in own directory, must be writeable for web server:
    php_value error_log "/afs/tu-chemnitz.de/home/urz/.../public_html/log/php_errors"
    
    # which errors: all = -1, most important = 8, the worst = 1
    php_value error_reporting -1
    # maximum size of the error file in bytes: unlimited = 0 … until memory is full
    php_value log_errors_max_len 1000000
    
    # Protect log file from web access
    <Files "php_errors">
      Require all denied
    </Files>
  • Please switch off again after the development phase.

Start Tag

The web server only interprets PHP instructions that are within special tags:
<?php echo "Hello"; ?>.
So far we also support the short form <? … ?> However, as this is not XML and XHTML compliant, all PHP programmers should use the long form above.

Check your scripts: For the test, enter the following in a .htaccess file in the PHP script directory:
php_flag short_open_tag off
At the moment you also need this if you use PHP instructions and XML processing instructions in a document., e.g. <?xml ... ?>