Werbung

Werbung

Werbung

Archive

Folge uns auf Twitter

Werbung

Jede Menge neue Twitter Follower bekommen. Die Software hat einen kostenlosen Trial Mode, der bis zu 250 Follower bringt.

Willkommen

Willkommen im PHP Archiv Blog! Hier gibts Infos zum Thema PHP Codeschnipsel und Tipps. Bei unserem Projekt phparchiv.de, finden Sie über 5700 Scripte.

KHK

Safe redirect mit PHP

Diese kleine Funktion garantiert, dass Besucher zu einer URL weitergeleitet werden. Zuerst versucht die Funktion, den Benutzer mit der header() Funktion weiterzuleiten, geht das nicht, wird Javascript und META-Refresh versucht. Wenn auch das nicht geht, wird ein Link angezeigt.

function safe_redirect($url, $exit=true) {
    // Only use the header redirection if headers are not already sent
    if (!headers_sent()){
        header('HTTP/1.1 301 Moved Permanently');
        header('Location: ' . $url);
        // Optional workaround for an IE bug (thanks Olav)
        header("Connection: close");
    }
    // HTML/JS Fallback:
    // If the header redirection did not work, try to use various methods other methods
    print '';
    print 'Redirecting you...';
    print '';
    print '';
print '';
 // If the javascript and meta redirect did not work,
 // the user can still click this link
 print 'You should be redirected to this URL:
';
 print "<a href="$url">$url</a>
";
 print 'If you are not, please click on the link above.
';
 print '';
    print '';
    // Stop the script here (optional)
    if ($exit) exit;
}

Quelle: jonasjohn.de

Das EXIF Thumbnail aus einem Bild extrahieren

Das kleine PHP-Script zeigt, wie man das EXIF Thumbnail aus einem Bild extrahieren kann.

// file to read
$file = 'test.jpg';
$image = exif_thumbnail($file, $width, $height, $type);
// width, height and type get filled with data
// after calling "exif_thumbnail"
if ($image) {
    // send header and image data to the browser:
    header('Content-type: ' .image_type_to_mime_type($type));
    print $image;
}
else {
    // there is no thumbnail available, handle the error:
    print 'No thumbnail available';
}

Quelle: jonasjohn.de

Perfect Quotes für WordPress

Das Perfect Quotes Widget für WordPress von Brandon Ferens von der Perfect Space, Inc. ermöglicht es Quotes einzugeben und diese dann in zufälliger Reihenfolge in einem speziellen Widget, mit Hilfe eines Shortcodes oder basiert auf Custom Post Types anzuzeigen.

Mit PHP checken ob HTTPS verfügbar ist

Eine weitere kleine Routine zum Checken ob HTTPS auf einem Server zur Verfügung ist. Eine andere Routine zum gleichen Zweck ist unter diesem Link zu finden.

if (isset($_SERVER['HTTPS']) &&
    strtolower($_SERVER['HTTPS']) == 'on') {
    $protokoll = 'https://';
  } else {
    $protokoll = 'http://';
}

Upload to Dropbox Plugin für WordPress

Das Upload to Dropbox Plugin für WordPress ermöglicht es Dateien direkt von WordPress aus in der Dropbox (Cloud Service) abzulegen.

Text Link zu anklickbaren Link umwandeln

Diese PHP Funktion verwandelt einen als Text eingefügten Link automatisch zu einem anklickbaren Link.

function dolink($subject) {
  $muster = "/(http:\/\/)?([a-zA-Z0-9\-.]+\.[a-zA-Z0-9\-]+([\/]([a-zA-Z0-9_\/\-.?&%=+])*)*)/";
  $ersetzen = "<a href="\&quot;http://$2\&quot;">$2</a>";
  return preg_replace($muster, $ersetzen, $subject);
}