user3086014
user3086014

Reputation: 4511

How to specify any host in php file?

I have an application created in PHP and MySQL hosted on a linux server . I have a db.inc file in which i have to specify the IP of that machine. How can I do that?

The contents are :

if (preg_match('/^(10.80.112.141|127.0.0.1|localhost|desktop|laptop)$/i', $_SERVER['SERVER_NAME'])) {
    // this is for my PC
    $dbusername = 'abc';
    $dbuserpass = 'abc123!';
    $dbprefix   = null;
    $http_server         = null;
    $https_server        = null;
    $https_server_suffix = null;
    $GLOBALS['log_xml_document'] = true;

How can I specify the hostname in file ?

Thanks

Upvotes: 1

Views: 254

Answers (1)

Alien Life Form
Alien Life Form

Reputation: 1944

If you are trying to connect to a DBMS on a hosted machine, and it does not work with localhost, it is most unlikely it will work with the hostname: 99% of the hosts are configured to listen on 127.0.0.1 (localhost) alone. Of the ones using a public interface, 99% still listen on localhost.

So before chasing IP issues, I'd try and make sure I can connect to the database with other means (command line, phpMyAdmin, ??)

But beware of the fact that you are weeding out localhost and 127.0.0.1 in you preg() match.

Upvotes: 1

Related Questions