为什么$_SERVER[';HTTP_HOST';]的计算结果未达到预期值


Why is $_SERVER['HTTP_HOST'] not evaluating to the expected value?

我正在开发一个Wordpress插件,$_SERVER['HTTP_HOST']有一些问题。

这指向的是完全不正确的东西。我在Wordpress安装的插件目录中调用它,它会出现http://www.richmindonline.com/testenvironment/wp-admin/www.richmindonline.com

我猜正确的路径应该是简单的http://www.richmindonline.com/testenvironment。有没有可能在我的插件文件中减少这一点,或者以某种方式创建一个重定向?

我想我不需要为此发布代码。如果你想让我发布部分代码,请告诉我。

更新

如果有帮助的话,这是安装根目录中的.htaccess文件。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /testenvironment/
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /testenvironment/index.php [L]
</IfModule>
# END WordPress

如果你想指向插件目录中的一个文件,我经常使用的方法之一是使用plugins_url函数,在下面的例子中,'yourfile.php'将被替换为你的唯一值,在这种情况下为'process.php':

$new_variable = plugins_url( 'yourfile.php', _FILE_ );

这会将变量(对于大多数Wordpress安装)设置为"http://YOURDOMAIN.com/wp-content/plugins/yourfile.php"。然而,使用plugins_url函数的好处是,如果有人安装了非标准的Wordpress,并且插件位于不同的文件夹中,该函数仍然可以确定正确的PHP文件在哪里。

如果您要查找的PHP文件在子文件夹中,只需将"yourfile.PHP"修改为"subfolder/yourfilephp"即可。

如果我误解了你想要实现的目标,而你只想要基本的url,Wordpress可以使用home_url()函数。请参阅(http://codex.wordpress.org/Function_Reference/home_url)。

获取插件文件夹中文件的另一种方法是使用plugin_dirurl()。

示例:

$new_variable = plugin_dir_url( _FILE_ ) . 'yourfile.php';

然后在表单中,使用:

<action = "<?php echo $new_variable; ?>">

这里概述了所有各种url函数:http://codex.wordpress.org/Function_Reference/site_url.

根据我的记忆,HTTP_HOST是由客户端提供的。

您可以随时使用函数对其进行修剪,或者使用$SERVER["SERVER_NAME"]和其他一些调整。

你可能想试试这个

$_SERVER['PATH_INFO']