Skip to content

Instantly share code, notes, and snippets.

@FuruholmAnton
Last active January 23, 2019 09:57
Show Gist options
  • Save FuruholmAnton/5643a8252f15fd6c58d5bdef48c05dcd to your computer and use it in GitHub Desktop.
Save FuruholmAnton/5643a8252f15fd6c58d5bdef48c05dcd to your computer and use it in GitHub Desktop.
function get_current_url($strip = true) {
// filter function
static $filter;
if ($filter == null) {
$filter = function($input) use($strip) {
$input = str_ireplace(array(
"\0", '%00', "\x0a", '%0a', "\x1a", '%1a'), '', urldecode($input));
if ($strip) {
$input = strip_tags($input);
}
// or any encoding you use instead of utf-8
$input = htmlspecialchars($input, ENT_QUOTES, 'utf-8');
return trim($input);
};
}
return 'http'. (($_SERVER['SERVER_PORT'] == '443') ? 's' : '')
.'://'. $_SERVER['SERVER_NAME'] . $filter($_SERVER['REQUEST_URI']);
}
<?php
static function url(){
return sprintf(
"%s://%s%s",
isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment