本文介绍了PHP如果是localhost,则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想知道是否有一些PHP代码可以判断它是从在线Web服务器运行还是从本地主机服务器运行.
我之所以这样问,是因为注释掉了将在本地主机而不是在线Web服务器上运行的代码.

例如,对于MYSQL,我的登录凭据与在线MYSQL凭据完全不同.
我正在从免费的在线Web服务器使用Filezilla传输FTP,Xampp传输本地主机,以及www.000webhost.com.只需将有效的localhost php文件通过FTP传输到Web服务器,而无需修改代码.

这就是我的想法.
我使用一些If,ElseIF语句来实现这一目标

Hello,

I was wondering if it is possible for some PHP code to tell if it is running from a online web server or from a local host server.
I ask this because commenting out code that will run on a localhost but not an online web server.

For example with MYSQL, my login credentials are completely different from the online MYSQL credentials.
I am using Filezilla for my FTP, Xampp for my localhost and www.000webhost.com from a free online web server. It would be nice just to FTP a working localhost php file to the web server without modifying the code.

Here is what I am thinking.
I use some If, ElseIF statements to achieve this

<?php

if ($localhost == TRUE) {

   mysql_connect("localhost", "test", "") or die(mysql_error());
   echo "Connected to Localhost<br />";
}

elseif (($localhost == FALSE) {

   mysql_connect("mysql3.000webhost.com", "username", "password") or die(mysql_error());
   echo "Connected to online server<br />";
}
?>

I don't know if this is the right way of doing this. Can someone please help? thanks.

推荐答案




这篇关于PHP如果是localhost,则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 10:29