<?php
$page = $_GET['page'];
$subpage = $_GET['subpage'];


##############
# Visitor Statistics

# Get Client/Remote IP and Hostname
if (getenv(HTTP_CLIENT_IP)){
        $visitorip=getenv(HTTP_CLIENT_IP);
}
else {
        $visitorip=getenv(REMOTE_ADDR);
}
$visitorhname=gethostbyaddr($visitorip);


# Get Http User Agent
if (getenv(HTTP_USER_AGENT)){
        $user_agent=getenv(HTTP_USER_AGENT);
}
else {
        $user_agent="No-User-agent-found";
}

# Get Http Referer
$referer=$_SERVER['HTTP_REFERER'];

# Get Request Uri
$uri=$_SERVER['REQUEST_URI'];

# Get Date/Time
$datetime=date("d/M/Y G:i:s");

# Compose logline
$logline="$visitorhname ; $visitorip ; $datetime ; $referer ; $uri ; $user_agent ;\n";

# Write to logfile
#$fp = fopen ("access.log", "a");
#fwrite ($fp, $logline);
#fclose ($fp);

# Send logline as mail
mail("johnny@wetteland.net", "New visitor on www.wetteland.net/index.php3", $logline, "From: homepage@$SERVER_NAME\nX-Mailer: PHP/" . phpversion());

##############

header("HTTP/1.0 301 Moved Permanently");
if ($page == "") {
    header("Location:http://www.wetteland.net/index.php");
}
if ($page <> "" and $subpage == "") {
    header("Location:http://www.wetteland.net/index.php?page=$page");
}
if ($subpage <> "") {
    header("Location:http://www.wetteland.net/index.php?page=$page&subpage=$subpage");
}
exit;

?>
