What is the way to determine whether a program runs locally or on a server

Source: Internet
Author: User
Good morning, my friends, how can I determine whether the program is running locally or on a server?
For example
Local Localhost/website or 127.0.0.1/website
Server www. Website Com

I think the goal is to have a variable $ A
When on the server is $a=3, when local $a=2, just for this.


Reply to discussion (solution)

Determine the value of $_server[' Http_host ']

Determine the value of $_server[' Http_host ']


I also want to use this, to determine whether it contains "localhost" or "127.0.0.1" and the like, but the total feeling seems to be not so cool.

Not inclusive but equal to
Why "localhost" or "127.0.0.1" or something like that?
Is it OK to judge if it equals www.website.com?

Not inclusive but equal to
Why "localhost" or "127.0.0.1" or something like that?
Is it OK to judge if it equals www.website.com?


Www.website.com can be a parameter after the Www.website.com/code=123&

You can print it out and see if it's clear.
echo $_server[' Http_host '];

You can print it out and see if it's clear.
echo $_server[' Http_host '];


You're saying, "Is it OK to judge if it equals www.website.com?" "But it could be with www and without www, and that's the problem.

I use Strpos to match $_server[' http_host ' and target domain or URL to automatically determine the operating environment

You can determine the MAC address. Different computers, Macs are different.

What is there to struggle with? A stake in your server is to support the two-level domain name, then the listing
In_array ($_server[' http_host '), array (domain Name list)
You can also use string comparisons

Anyway, you don't have to be behind closed doors.



You can print it out and see if it's clear.
echo $_server[' Http_host '];


You're saying, "Is it OK to judge if it equals www.website.com?" "But it could be with www and without www, and that's the problem.

Thank you, your answer solved the problem, not behind closed doors, very good.

What is there to struggle with? A stake in your server is to support the two-level domain name, then the listing
In_array ($_server[' http_host '), array (domain Name list)
You can also use string comparisons

Anyway, you don't have to be behind closed doors.




You can print it out and see if it's clear.
echo $_server[' Http_host '];


You're saying, "Is it OK to judge if it equals www.website.com?" "But it could be with www and without www, and that's the problem.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.