PHP return different content based on domain names and IP

  • Encountered a fun thing, the contents of other people's IP and domain name access someone else's return turned out different. I suddenly felt a lot of fun, and very curious. Their own research about the next, simply write it ~
  • An IP and a domain name,
  • Talk about what public IP domain name is not bound, but you can access the contents of the IP through no record of a domain name. Methods: The local hosts file is in the public domain and IP binding. This is very basic, simple mention. If the phase so that others can also access the domain name of your project, configure the hosts file on his computer, binding domain and your IP.
  • Others by configuring the hosts file can be accessed through the domain name of your project, assuming there is such a situation, I have a project belonging to private IP on this server, I just want to see a person designated by such armor, in fact, you can put a domain name tells, let armor configure the hosts file, and then give you access to the project's domain name. So even if someone knows the IP also can not access your project. Only people who know the domain name to access your project. How to achieve it? look down
    // the PHP or through the domain name, to be a simple example here, can use regular, you made a rule to match IP domain and is determined by the IP host according to the user's request. 
    IF ( the strpos ( $ _SERVER ! [ 'HTTP_HOST'], '127.0.0.1') == to false ) {
         echo 111111; Exit ; // accessed by IP 111 returns let him see other content 
    } ELSEIF ( the strpos ( $ _SERVER ! [ 'HTTP_HOST'], 'localhost') == false ) {
         echo 'localhost';   // accessed by specifying the domain name, let him visit the project 
    } the else {
         echo 'ERR'; Exit ; 
    } 
    
    echo 'here you can write the project content ';

    Through the above simple to achieve a return different content based on domain names and IP. For example, you do not want to see documentation of the project owner, you can use people in this way to see the project team. (Of course, the domain name to be kept confidential oh ~)

Guess you like

Origin www.cnblogs.com/bneglect/p/12072329.html