PHP Code: IP trotz Proxy

Gibt die IP-Adresse aus, obwohl der Besucher über ein Proxy verbunden ist.

<?php

function getproxip() {
 if (getenv("HTTP_X_FORWARDED_FOR")) {
  $realip = getenv("HTTP_X_FORWARDED_FOR");
 } else {
  $realip = getenv("REMOTE_ADDR");
 }
  return $realip;
}

?>

PHP Code: Verzeichnis listing

Einfache Funktion um einen Ordner auszulesen.

<?php

function get_dirlist ($path = '') {
 if (empty($path)) $path = "./";
  $dirlist = array();
  $d = dir($path);
  while($entry=$d->read()) {
   if ($entry=='.' OR $entry=='..') continue;
   if ($entry == 'images') continue;
   if (is_dir($entry))  $dirlist[] = $entry;
  }
  $d->close();
  sort($dirlist);
  @reset($dirlist);

  return $dirlist;
}

?>

PHP Code: Verzeichnis samt Inhalt loeschen

Mit diesem Schnipsel kann man ein Verzeichnis samt Inhalt löschen, vorrausgesetzt ist das die Zugriffsrechte entsprechend sind.

<?php 

function deltree($dir) {
 if($objs = glob($dir."/*")){
  foreach($objs as $obj) {
   is_dir($obj)? deltree($obj) : unlink($obj);
  }
 }
 rmdir($dir);
}

?>

PHP Code: RGB in Hex Konvertieren (RGB to Hex)

Einfache Funktion um von RGB in Hexadezimal umzuwandeln. (RGB to Hex)

<?php

function rgb2hex($rgb) {
 if ($rgb == "" || (!$rgb)) return "#FFFFFF";
 $hex = split(",",$rgb);

 $r = dechex($hex[0]);
 $g = dechex($hex[1]);
 $b = dechex($hex[2]);

 return "#".$r.$g.$b;
}
?>

PHP Code: Server Online-Check

Dieses Script prüft, ob eine IP-Adresse erreichbar ist.

<?php

$ip = "128.0.0.1";

$fp = @fsockopen ($ip,80,$errno,$errstr,30);
if (!$fp) {
 echo '<font color="red">Offline</font>';
} else {
 echo '<font color="green">Online</font>';

 fclose($fp);
}

?>

PHP Code: Bild-Größen Limit

Dieses Script begrenzt die Größe eines Bildes auf den, in der Funktion definierten Wert.

<?php

function piclimiter ($bild, $size) {
 $imginfo = @getimagesize($bild);

 if(($imginfo[0] != 0 && $imginfo[0] > $size) || ($imginfo[1] != 0 && $imginfo[1] > $size)) {
  if($size != 0) {
   $div1 = $size / $imginfo[0];
   $div2 = $size / $imginfo[1];
  } else {
   $div1 = 1;
   $div2 = 1;
  }
  if($div1 < $div2) {
   $imgwidth = $size;
   $imgheight = round($imginfo[1]*$div1);
  } else {
   $imgheight = $size;
   $imgwidth = round($imginfo[0]*$div2);
  }

 $picture = '<img src="'.$bild.'"width="'.$imgwidth.'"height="'.$imgheight.'" border="0">';
 } else {
  $picture = '<img src="'.$bild.'" border="0">';
 }
 return $picture;
}

?>

PHP Code: ICQ Online Check

Hiermit kannst du überprüfen ob eine ICQ Nummer online ist. Die Ausgabe erfolgt in Text.

<?php

function GetICQ($uin) {
 if (!is_numaeric($uin)) return FALSE;
 $fp = fsockopen('web.icq.com',80,&$errno,&$errstr,8);
 if (!$fp) return FALSE;
 $request = "HEAD /whitepages/online?icq=$uin&img=5 HTTP/1.0\r\n"."Host: web.icq.com\r\n"."Connection: close\r\n\r\n";
 fputs($fp, $request);

 do {
  $response = fgets($fp, 1024);
 } while (!feof($fp) && !stristr($response,'Location'));

 fclose($fp);

 if (strstr($response, '4367'))
   return 'online';
 if (strstr($response, '4349'))
   return 'offline';
 if (strstr($response, '4386'))
   return 'disabled';

 return FALSE;
}

?>
Dezember 21st, 2010 | 0 Comments
Category: Server und System | Tags: , , , , ,