[wp-trac] [WordPress Trac] #25239: $_SERVER['SERVER_NAME'] not a reliable when generating email host names
WordPress Trac
noreply at wordpress.org
Wed Aug 17 08:25:43 UTC 2016
#25239: $_SERVER['SERVER_NAME'] not a reliable when generating email host names
-------------------------------------------------+-------------------------
Reporter: layotte | Owner:
Type: defect (bug) | SergeyBiryukov
Priority: normal | Status: reviewing
Component: Mail | Milestone: Future
Severity: normal | Release
Keywords: has-patch dev-feedback needs- | Version: 3.8
testing | Resolution:
| Focuses:
-------------------------------------------------+-------------------------
Comment (by mensmaximus):
Can we fix this for 4.7 please?
There are several places in WordPress where we rely on
`$_SERVER['SERVER_NAME']` or `$_SERVER['HTTP_HOST']`. While I personally
never trust in `$_SERVER['SERVER_NAME']` I understand some feel
uncomfortable with `$_SERVER['HTTP_HOST']` either.
Given the fact that `home_url` and `blog_id` are always set and can be
trusted, introducing a new function might be a solution:
{{{
#!php
function get_current_domain() {
return parse_url( get_home_url( get_current_blog_id() ),
PHP_URL_HOST );
}
}}}
The function name follows the syntax from other `get_` functions in
WordPress. It's name says what it does. It relies on WordPress core
functions and settings that always exist. It works with PHP down to 4.0.
So instead of using `$_SERVER['SERVER_NAME']` or `$_SERVER['HTTP_HOST']`
you could use `get_current_domain()`.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/25239#comment:21>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list