Skip to content

Instantly share code, notes, and snippets.

@lenivene
Last active March 16, 2019 15:38
Show Gist options
  • Save lenivene/78c0b89b590a439c53591afd32a34bd3 to your computer and use it in GitHub Desktop.
Save lenivene/78c0b89b590a439c53591afd32a34bd3 to your computer and use it in GitHub Desktop.
Função para verificar se é servidor de teste (localhost)
<?php
/**
* Verificar servidor
* @return null Retorna se tiver erro, se preferir troque para class Exception.
* @return true | false Retorna true para localhost e false para servidor
*
* @version 1.0
* @author Lenivene Bezerra
*/
function isServerLocal(){
if( !isset( $_SERVER['SERVER_ADDR'] ) || ! isset( $_SERVER['REMOTE_ADDR'] ) || ! function_exists( 'getcwd' ) )
return null;
$isServerLocal = (
$_SERVER['SERVER_ADDR'] === $_SERVER['REMOTE_ADDR']
&&
substr_compare( getcwd(), ":", 1, 1 ) == 0
);
return (bool) $isServerLocal;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment