Jump to main content
University Computer Centre
Modules
University Computer Centre 

Notes on PHP Modules

Working with Databases

With PHP, access to databases is easily possible → Database service of the URZ for MySQL and PostgreSQL databases.

Documentation

Security

Checking E-mail Addresses

If e-mail addresses are requested in forms, they must be checked before use. Use the TUCAL function check_mailadr() for this purpose.

Checking e-mail addresses

Sending E-mail

PHP can also be used to send e-mails. But attention: This should not be a function that is publicly accessible or sends a lot of e-mails - if in doubt, please ask! To ensure that the sender address is set correctly and the character set is determined correctly, there is a separate function of this server: tuc_mail() – See description sending e-mails:

Script for Sending an E-mail
If you cannot or do not want to use the tuc_mail() function, please be sure to consider the
notes in this example
.

With tuc_mail() only text mails without attachments can be sent. For advanced functions, use the PHPMailer module on the central servers:

  • Example
  • Tutorial

Disguising E-mail Addresses

E-mail addresses must not appear in plain text on web pages so that advertising mail senders cannot "collect" e-mail addresses. A PHP function can be used to disguise e-mail addresses (and also other data, such as phone numbers):

<?php   require_once('php/mail.inc');
        # First subdomain displayed
        echo prot_mailadr('john.doe@s2006.tu-chemnitz.de');
        # cut away after the @:
        echo prot_mailadr('jane.doe@s2010.tu-chemnitz.de'1);

        # this also works for a phone number, the 2nd argument: how many chars are displayed:
        echo prot_mailadr('0371 / 531 12345'11);
?>

The generated website states:

Before the address or data is displayed, you have to type in a code – except for logged in users.

Features for VoIP Telephony

The VoIP telephones of the TU Chemnitz can be controlled via the web. This is how the dialling of a telephone number on your telephone (with personal registration) can be prepared with a (Click2Dial). There is also a prepared PHP function for this purpose: telnu().

<?php   require_once('php/tel.inc');
        echo "Give us a call: " telnu('123456');
?>

LDAP Data Query

The central LDAP server of the TU Chemnitz contains essential information about users of the TU. These can also be queried with PHP functions. For your convenience, there are some predefined functions that you can use.

Note: This is personal data. It is essential that you observe the corresponding data protection regulations!

To use it, the file php/ldap.inc must be included in the page header:

# Embed LDAP functions
require_once('php/ldap.inc');
See also:

Query Data for a Login Indicator

$info = ldap_userinfo('login_identifier');

Queries the LDAP directory for data for the user with 'login_identifier' and returns a field with corresponding data.

Return Value

An array $info with attributes and values:

$info['name']
First name Surname (UTF-8)
$info['nachname']
Surname (UTF-8)
$info['vorname']
First name (UTF-8)
$info['mail']
E-mail address
$info['tel']
Telephone number
$info['ou']
Enrolled faculty or structural unit
$info['ous']
array with possibly several structural units of the person
$info['ounumber']
Structure number
$info['ounumbers']
array with possibly several structure numbers of the person
$info['login']
Log in identifier
$info['addresse']
Street, postcode City
$info['raum']
Room number
$info['raumlink']
Link to Campusfinder for Room
$info['titel']
Academic title (if registered)
$info['gebaeude']
obsolete: Building
Requesting user data for login identifiers "otto": Output
PHP instructions

Please note: The public directory contains data of all TU employees. Students can object to the publication of the data - this data is then not accessible. Data of employees on leave or external persons are also not retrievable.

Query Multiple Records According to a Filter

$infos = ldap_info('filter');

You can query records of multiple people using a LDAP filter.

Return Value

A two-dimensional array $infos sorts by surname, per user found a field with attributes as with ldap_userinfo() (see above):

$info[0]['name']
First name Surname (UTF-8) of person 1
$info[0]['nachname']
Surname (UTF-8) of person 1
$info[1]['name']
First name Name (UTF-8) of person 2
List of persons with e-mail and telephone for structure number 1342…: Output
PHP instructions

Query Data for a Public LDAP Group

$members = ldap_groupinfo('grp:name');

Queries the LDAP directory for the members of the group named 'grp:name' and returns a field with corresponding data.

Return value

An array $members with the login identifiers of the group members.

Graphics and PDF Documents

Our PHP installation contains the extension GD for handling graphics. The commercial PDFlib for editing PDF files is no longer available. To create PDF documents please use LaTeX – Command: pdflatex.

PHP calculates graphics with the GD extension
The PHP instructions:
gd_en.php
FunctionGraph.class.php

Social Media Functions: "Like!" etc.

This makes it very easy for web authors to integrate "Share" and "Like!" from Facebook as well as recommendations to Twitter and LinkedIn into a website. The 2-click solution for more data protection (only German) of the Heise publishing house was implemented. You can see the representation and function on this page below.

  • Advantages: When visiting our websites, no data of our web visitors is transmitted to the services. Only when the user clicks, the functions are integrated and data is transmitted to the providers of the social services.
  • Disadvantage: The visitor must click twice to actually trigger the action.

To embed this function, the file php/sm.inc must be included:

# Use of social media functions
require_once('php/sm.inc');
Please note:
  • Browser must support JavaScript, otherwise these functions will not take effect.
  • Website must embed jQuery (this is possible by default).

Functions

string sm_share([string $orientation [, NULL, NULL, array $services]])

Generates HTML/Script code for embedding Facebook/Twitter/LinkedIn Functions.
Parameter
$orientation 'h' (Default), 'v' Appearance: horizontal (side by side), vertical (below each other)
NULL Leave empty is not used,
empty string is also possible ('')
NULL Leave empty is not used,
empty string is also possible ('')
$services array() Which services, e. g. array('facebook', 'twitter', 'linkedin');
Values see description, option data-services (not everything was implemented by us)
Return value

HTML text, can be output with echo.

Displays the social networking functions side by side.

<?php require_once('php/sm.inc');
      echo sm_share();
?>

Displays the social networking functions among each other.

<?php require_once('php/sm.inc');
      echo sm_share('v'NULLNULL, array('twitter''facebook''linkedin'));
?>