Auflistung einiger PHP Codeschnipsel

Bild aus Verzeichnis auslesen:

<?PHP
$path = "pics"; //Bildverzeichnis

$verz = opendir($path);

$pics = array ("0");
while($file = readdir($verz))
{
if($file != ".." && $file != "." && !empty($file)) $pics[] = $file;
}

if(isset($_GET['showimg']) && empty($_GET['showimg']) OR !isset($_GET['showimg']))
{
$_GET['showimg'] = 1;
}
$nextimg = $_GET['showimg'];
if($nextimg < (count($pics)-1)) $nextimg++;

//Bild ausgeben:
echo "<a href=\"".$_SERVER['PHP_SELF']."?showimg=".$nextimg."\"><img src=\"".$path."/".$pics[$_GET['showimg']]."\" alt=\"Bild\" style=\"border:0;\" /></a>";
?>



Datum und Uhrzeit ausgeben:

<?PHP
$datum = date("d.n.Y"); //aktuelles Datum wird an $datum übergeben
$zeit = date("G:i:s"); //aktuelle Uhrzeit an $zeit übergeben
echo "Heute ist der ".$datum.". Es ist ".$zeit." Uhr."; //Ausgabe
?>


Atomuhrzeit:
<?php
function atomtime() {
$file = @file("http://www.uni-leipzig.de/cgi-bin/date/index.htm");
if (!$file) $time = time();
else
$time = strtotime($file[0]);

return $time;
}
?>



IP Sperre (Code muß ganz oben eingefügt werden):

<?php
function ipCheck($ip) {
if(in_array($_SERVER['REMOTE_ADD'], $ip)) {
return true;
} else {
return false;
}
}

//Gesperrte IPs
$ip = array("242.168.30.260", "182.359.70.270", "132.251.120.280", "182.159.120.290", "212.128.10.299");
if(ipCheck($ip)) {
header("Location: andereSeite.php");
exit;
}

?>



Einfache Bannerrotation 3 Banner):


<?php
$ads = array(
array("Banner" => "<a href=\"http://www.webseite.de\" target=\"_blank\"><img src=\"banner/banner1.jpg\" alt=\"\" width=\"468\" height=\"60\" border=\"0\" /></a>"),
array("Banner" => "<a href=\"http://www.webseite.de\" target=\"_blank\"><img src=\"banner/banner1.jpg\" alt=\"\" width=\"468\" height=\"60\" border=\"0\" /></a>"),
array("Banner" => "<a href=\"http://www.webseite.de\" target=\"_blank\"><img src=\"banner/banner1.jpg\" alt=\"\" width=\"468\" height=\"60\" border=\"0\" /></a>")
);
srand ((double)microtime()*10000);
$maxwert = count($ads)-1;
$nr = rand(0,$maxwert);
echo $ads[$nr][Banner];
?>