The htaccess file located in the root of your domain can provide username/ password access control to specific pages or entire folders though basic it is secure enough for most applications.
After that you move into the realms of encryption and databases where everything is scambled and even if somebody does manage to break in the information is unreadable.
Grabbing the visitors IP can be difficult sometimes, no one single method allways works so here is a complete IP reading script for PHP.
Code:
/ The function to get the visitor's IP.
function getUserIP()
{
//check ip from share internet
if (!empty($_SERVER['HTTP_CLIENT_IP']))
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
//to check ip is pass from proxy
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
//The users IP is...
$visitorsIp = getUserIP();