adding new psm_build_url() function to create clean urls with params

This commit is contained in:
Pepijn Over 2014-03-14 15:12:00 +01:00
parent bd016caf13
commit f8f3b38708
1 changed files with 30 additions and 0 deletions

View File

@ -339,6 +339,36 @@ function psm_build_mail($from_name = null, $from_email = null) {
return $phpmailer;
}
/**
* Generate a new link to the current monitor
* @param array $params key value pairs
* @param boolean $urlencode urlencode all params?
* @return string
*/
function psm_build_url($params = array(), $urlencode = true) {
$defports = array(80, 443);
$url =
($_SERVER['SERVER_PORT']==80 ? 'http' : 'https').'://'.
$_SERVER['HTTP_HOST'];
if(!in_array($_SERVER['SERVER_PORT'], $defports)) {
$url .= ':' . $_SERVER['SERVER_PORT'];
}
$url .= dirname($_SERVER['SCRIPT_NAME']) . '/';
if($params != null) {
$url .= '?';
foreach($params as $k => $v) {
if($urlencode) {
$v = urlencode($v);
}
$url .= '&' . $k . '=' . $v;
}
}
return $url;
}
###############################################
#
# Debug functions