PHP - Snippets: Unterschied zwischen den Versionen
Aus Wikizone
| Zeile 1: | Zeile 1: | ||
| + | == Marker Replacement == | ||
| + | <pre> | ||
| + | function replace_markers($template,$arrMarkers){ | ||
| + | // Platzhalter mit den Benutzereingaben ersetzen | ||
| + | $sCalib_as_offered = '<p>Request for customized calibration</p>'; | ||
| + | $sCalib_as_datasheet = '<p>Calibration will be performed based on current specifications as stated in data sheet</p>'; | ||
| + | $sAdditional_service = '<h3>Only for calibration request</h3><strong>End user would like to have additional services:</strong></p>'; | ||
| + | $sCalib_justify = '<p>Standard calibration (ISO) with adjustment (with additional charges)</p>'; | ||
| + | $sFw_update = '<p>Firmware update (free of charge)</p>'; | ||
| + | |||
| + | if($arrMarkers[calib_type] == 'calib_as_offered') $template = str_replace( '###CALIB_TYPE###', $sCalib_as_offered, $template ); | ||
| + | if($arrMarkers[calib_type] == 'calib_as_datasheet') $template = str_replace( '###CALIB_TYPE###', $sCalib_as_datasheet, $template ); | ||
| + | |||
| + | if($arrMarkers[additional_service]) $template = str_replace( '###ADDITIONAL_SERVICE###', $sAdditional_service, $template); | ||
| + | if($arrMarkers[calib_justify]) $template = str_replace( '###CALIB_JUSTIFY###', $sCalib_justify, $template ); | ||
| + | else $template = str_replace( '###CALIB_JUSTIFY###', '', $template ); | ||
| + | |||
| + | if($arrMarkers[fw_update]) $template = str_replace( '###FW_UPDATE###', $sFw_update, $template ); | ||
| + | else $template = str_replace( '###FW_UPDATE###', '', $template ); | ||
| + | |||
| + | foreach($arrMarkers as $key => $val){ | ||
| + | if($val == '0')$val = ''; | ||
| + | $val = iconv("UTF-8","UTF-8//IGNORE",$val); | ||
| + | $template = str_replace( '###'.strtoupper($key).'###', htmlspecialchars( $val ), $template ); | ||
| + | } | ||
| + | |||
| + | $template = str_replace( '###FNAME1###', htmlspecialchars( $arrMarkers[fname1] ), $template ); | ||
| + | $template = str_replace( '###RMA_NUM###', $rma_num, $template ); | ||
| + | $template = str_replace( '###NACHRICHT###', htmlspecialchars( $nachricht ), $template ); | ||
| + | //echo $template; | ||
| + | return $template; | ||
| + | } | ||
| + | |||
| + | </pre> | ||
| + | |||
== Clean up POST und GET == | == Clean up POST und GET == | ||
Zusätzliche Sicherheit für Post und Get. | Zusätzliche Sicherheit für Post und Get. | ||
Version vom 18. Februar 2014, 13:46 Uhr
Marker Replacement
function replace_markers($template,$arrMarkers){
// Platzhalter mit den Benutzereingaben ersetzen
$sCalib_as_offered = '<p>Request for customized calibration</p>';
$sCalib_as_datasheet = '<p>Calibration will be performed based on current specifications as stated in data sheet</p>';
$sAdditional_service = '<h3>Only for calibration request</h3><strong>End user would like to have additional services:</strong></p>';
$sCalib_justify = '<p>Standard calibration (ISO) with adjustment (with additional charges)</p>';
$sFw_update = '<p>Firmware update (free of charge)</p>';
if($arrMarkers[calib_type] == 'calib_as_offered') $template = str_replace( '###CALIB_TYPE###', $sCalib_as_offered, $template );
if($arrMarkers[calib_type] == 'calib_as_datasheet') $template = str_replace( '###CALIB_TYPE###', $sCalib_as_datasheet, $template );
if($arrMarkers[additional_service]) $template = str_replace( '###ADDITIONAL_SERVICE###', $sAdditional_service, $template);
if($arrMarkers[calib_justify]) $template = str_replace( '###CALIB_JUSTIFY###', $sCalib_justify, $template );
else $template = str_replace( '###CALIB_JUSTIFY###', '', $template );
if($arrMarkers[fw_update]) $template = str_replace( '###FW_UPDATE###', $sFw_update, $template );
else $template = str_replace( '###FW_UPDATE###', '', $template );
foreach($arrMarkers as $key => $val){
if($val == '0')$val = '';
$val = iconv("UTF-8","UTF-8//IGNORE",$val);
$template = str_replace( '###'.strtoupper($key).'###', htmlspecialchars( $val ), $template );
}
$template = str_replace( '###FNAME1###', htmlspecialchars( $arrMarkers[fname1] ), $template );
$template = str_replace( '###RMA_NUM###', $rma_num, $template );
$template = str_replace( '###NACHRICHT###', htmlspecialchars( $nachricht ), $template );
//echo $template;
return $template;
}
Clean up POST und GET
Zusätzliche Sicherheit für Post und Get.
function clean($elem) {
/* used to add some security to get and post vars */
if(!is_array($elem))
$elem = htmlentities($elem,ENT_QUOTES,"UTF-8");
else
foreach ($elem as $key => $value)
$elem[$key] = $this->clean($value);
return $elem;
}
$_CLEAN['GET'] = clean($_GET);
$_CLEAN['POST'] = clean($_POST);
IP Adresse Abfragen
public static function get_ip() {
$REMOTE_ADDR = $_SERVER['REMOTE_ADDR'];
if ( ! empty( $_SERVER['X_FORWARDED_FOR'] ) ) {
$X_FORWARDED_FOR = explode(',', $_SERVER['X_FORWARDED_FOR'] );
if ( ! empty( $X_FORWARDED_FOR ) ) {
$REMOTE_ADDR = trim( $X_FORWARDED_FOR[0] );
}
}
elseif ( ! empty($_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
$HTTP_X_FORWARDED_FOR= explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
if ( ! empty($HTTP_X_FORWARDED_FOR ) ) {
$REMOTE_ADDR = trim($HTTP_X_FORWARDED_FOR[0]);
}
}
return preg_replace('/[^0-9a-f:\., ]/si', '', $REMOTE_ADDR);
}