Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WordPress wp-config.php,如果else在某些计算机上不工作_Php_Mysql_Database_Wordpress_If Statement - Fatal编程技术网

WordPress wp-config.php,如果else在某些计算机上不工作

WordPress wp-config.php,如果else在某些计算机上不工作,php,mysql,database,wordpress,if-statement,Php,Mysql,Database,Wordpress,If Statement,我在本地和远程设置中有相同的wp配置 下面的代码检查用户是否正在加载站点的本地或实时版本,并使用适当的数据库凭据: /* * Unified variables */ $hostname = 'localhost'; $chartset = 'utf8'; *etcetc.... /* * Check for the current environment */ if ($_SERVER["HTTP_HOST"] === 'example.

我在本地和远程设置中有相同的wp配置

下面的代码检查用户是否正在加载站点的本地或实时版本,并使用适当的数据库凭据:

/* 
 * Unified variables 
 */   
$hostname = 'localhost';  
$chartset = 'utf8';  
*etcetc....

/* 
 * Check for the current environment 
 */  
if ($_SERVER["HTTP_HOST"] === 'example.dev') {  
  $db_name = 'example';  
  $user_name = 'root'; 
  $password = 'root';  
} else 
{  
  $db_name = 'remote_db_name';
  $user_name = 'remote_db_user';
  $password = 'remote_db_pw; 
}  
 
// ** MySQL settings - You can get this info from your web host ** //  
/** The name of the database for WordPress */  
define('DB_NAME', $db_name);  
  
/** MySQL database username */  
define('DB_USER', $user_name);  
//etc....
这个有效。但是如果我将if命令翻转到另一个方向,那么

if ($_SERVER["HTTP_HOST"] === 'example.com') {  
  $db_name = 'example';  
  $user_name = 'root'; 
  $password = 'root';  
} else 
{  
  $db_name = 'remote_db_name';
  $user_name = 'remote_db_user';
  $password = 'remote_db_pw; 
}  
它适用于我的几个不同的设备和连接,但对于我的客户端,它不再工作。你知道为什么会这样吗

我需要的是另一种方式,因为我正在用其他带有URL的设备测试我的设计,比如: 如果所有的本地开发工具都像example.dev和if-else中的“else”一样,那就更好了

什么会导致我的客户端出现数据库错误?他已经尝试了几种设备和连接,如果live server是“else”而不是“the”,问题就会消失

if ($_SERVER["HTTP_HOST"] === 'example.com') {  

也许考虑一下:

if ( stristr( $_SERVER['HTTP_HOST'], 'example.dev' ) ) {

}

这将适用于您上面给出的示例。你甚至可以试试example.com作为针。我很好奇www.是否会出现在HTTP_主机上。如果是这样的话,这就是你的客户有问题的原因吗?

很好!事实上,我在我的网站上回显了$_服务器[“HTTP_主机”),我的客户端正在浏览该网站的www版本。因为我正在使用上一个解决方案,所以自动wordpress重定向停止工作。