Archive | March, 2006

HTML : Codes

17 Mar

1. Want to get rid of the line underneath your links?

You can remove them easily by adding the following code between the </title> and </head> tags in your page.

<style type=”text/css”><!–A:link {text-decoration:none}
A:visited {text-decoration:none}–> </style>

Note: this effect only works in Netscape 4.0+ and IE 3.0+

2. Refresh page

<META HTTP-EQUIV=”Refresh” CONTENT=”0; URL=http://try.htm”>

3. Pop-up new browser

<body onload=”init()”>

4. Embed Midi

<embed src=”cindai.mid” loop=”true” autostart=”true” width=”128″
height=”128″ hidden>

5. Favourite Icon

<link rel=”shortcut icon” href=”/i/ico/favicon.ico”>

ASX Code

17 Mar

<ASX>

<ENTRY>
<TITLE> “”</TITLE>
<REF href=”http://www.xxx.com/xxx.wmv”/&gt;
</ENTRY>

</ASX>

PHP : Form To Mail

17 Mar

<?php

/*

Updated 29th November 2003
Previous version allowed spammers to hijack this script and
send emails from an external site – this is now prevented

Instructions:

Change the email address to your own.

$empty_fields_message and $thankyou_message can be changed
if you wish.

*/

// Change to your own email address
$your_email = “you@example.com”;

// This is what is displayed in the email subject line
// Change it if you want
$subject = “Message via your contact form”;

// This is displayed if all the fields are not filled in
$empty_fields_message = “<p>Please go back and complete all the fields in the form.</p>”;

// This is displayed when the email has been sent
$thankyou_message = “<p>Thankyou. Your message has been sent.</p>”;

// You do not need to edit below this line

$name = stripslashes($_POST[‘txtName’]);
$email = stripslashes($_POST[‘txtEmail’]);
$message = stripslashes($_POST[‘txtMessage’]);

if (!isset($_POST[‘txtName’])) {

?>

<form method=”post” action=”<?php echo $_SERVER[‘REQUEST_URI’]; ?>”>

<p><label for=”txtName”>Name:</label><br />
<input type=”text” title=”Enter your name” name=”txtName” /></p>

<p><label for=”txtEmail”>Email:</label><br />
<input type=”text” title=”Enter your email address” name=”txtEmail” /></p>

<p><label for=”txtMessage”>Your message:</label><br />
<textarea title=”Enter your message” name=”txtMessage”></textarea></p>

<p><label title=”Send your message”>
<input type=”submit” value=”Send” /></label></p>

</form>

<?php

}

elseif (empty($name) || empty($email) || empty($message)) {

echo $empty_fields_message;

}

else {

// Stop the form being used from an external URL
// Get the referring URL
$referer = $_SERVER[‘HTTP_REFERER’];
// Get the URL of this page
$this_url = “http://&#8221;.$_SERVER[‘HTTP_HOST’].$_SERVER[“REQUEST_URI”];
// If the referring URL and the URL of this page don’t match then
// display a message and don’t send the email.
if ($referer != $this_url) {
echo “You do not have permission to use this script from another URL.”;
exit;
}

// The URLs matched so send the email
mail($your_email, $subject, $message, “From: $name <$email>”);

// Display the thankyou message
echo $thankyou_message;

}

?>

PHP : Simple Guestbook

17 Mar

<?php

/*

Create the table in your MySQL database:

CREATE TABLE guests (
id int(10) NOT NULL auto_increment,
name varchar(50) NOT NULL,
message varchar(255) NOT NULL,
date timestamp(14) NOT NULL,
PRIMARY KEY (id)
)

Change the database login settings to your own

The script is now ready to run

*/

// Change these to your own database settings
$host = “localhost”;
$user = “username”;
$pass = “password”;
$db = “database”;

mysql_connect($host, $user, $pass) OR die (“Could not connect to the server.”);
mysql_select_db($db) OR die(“Could not connect to the database.”);

$name = stripslashes($_POST[‘txtName’]);
$message = stripslashes($_POST[‘txtMessage’]);

if (!isset($_POST[‘txtName’])) {

$query = “SELECT id, name, message, DATE_FORMAT(date, ‘%D %M, %Y @ %H:%i’) as newdate FROM guests ORDER BY id DESC”;
$result = mysql_query($query);

while ($row = mysql_fetch_object($result)) {

?>

<p><strong><?php echo $row->message; ?></strong>
<br />Posted by <?php echo $row->name; ?> on <?php echo $row->newdate; ?></p>

<?php

}

?>

<p>Post a message</p>

<form method=”post” action=”<?php echo $_SERVER[‘REQUEST_URI’]; ?>”>

<p><label for=”txtName”>Name:</label><br />
<input type=”text” title=”Enter your name” name=”txtName” /></p>

<p><label for=”txtMessage”>Your message:</label><br />
<textarea title=”Enter your message” name=”txtMessage”></textarea></p>

<p><label title=”Send your message”>
<input type=”submit” value=”Send” /></label></p>

</form>

<?php

}

else {

// Adds the new entry to the database
$query = “INSERT INTO guests SET message=’$message’, name=’$name’, date=NOW()”;
$result = mysql_query($query);

// Takes us back to the entries
$ref = $_SERVER[‘HTTP_REFERER’];
header (“Location: $ref”);
}

?>

PHP : Class to draw Text as PNG Graphic

17 Mar

<?
/*
TextPNG Class. Class to draw text using TTF font and output PNG graphic.
Copyright (C) 2000 Herman Veluwenkamp

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Copy of GNU Lesser General Public License at: http://www.gnu.org/copyleft/lesser.txt
Contact author at: hermanV@mindless.com

*/

/*
To draw the PNG – call this script with a URL like the following:

http://www.yoursite.com/text_png.php3?msg=testing+class&rot=15&size=48&font=fonts/ARIAL.TTF
*/

class textPNG {
var $font = ‘TIMES.TTF’; //default font. put in full path.
var $msg = “undefined”; // default text to display.
var $size = 24;
var $rot = 0; // rotation in degrees.
var $pad = 0; // padding.
var $transparent = 1; // transparency set to on.
var $red = 0; // white text…
var $grn = 0;
var $blu = 0;
var $bg_red = 255; // on black background.
var $bg_grn = 255;
var $bg_blu = 255;

function draw() {
$width = 0;
$height = 0;
$offset_x = 0;
$offset_y = 0;
$bounds = array();
$image = “”;

//$this->msg = date (“h:i:s”);

// determine font height.
$bounds = ImageTTFBBox($this->size, $this->rot, $this->font, “W”);
if ($this->rot < 0) {
$font_height = abs($bounds[7]-$bounds[1]);
} else if ($this->rot > 0) {
$font_height = abs($bounds[1]-$bounds[7]);
} else {
$font_height = abs($bounds[7]-$bounds[1]);
}

// determine bounding box.
$bounds = ImageTTFBBox($this->size, $this->rot, $this->font, $this->msg);
if ($this->rot < 0) {
$width = abs($bounds[4]-$bounds[0]);
$height = abs($bounds[3]-$bounds[7]);
$offset_y = $font_height;
$offset_x = 0;

} else if ($this->rot > 0) {
$width = abs($bounds[2]-$bounds[6]);
$height = abs($bounds[1]-$bounds[5]);
$offset_y = abs($bounds[7]-$bounds[5])+$font_height;
$offset_x = abs($bounds[0]-$bounds[6]);

} else {
$width = abs($bounds[4]-$bounds[6]);
$height = abs($bounds[7]-$bounds[1]);
$offset_y = $font_height;;
$offset_x = 0;
}

$image = imagecreate($width+($this->pad*2)+1,$height+($this->pad*2)+1);

$background = ImageColorAllocate($image, $this->bg_red, $this->bg_grn, $this->bg_blu);
$foreground = ImageColorAllocate($image, $this->red, $this->grn, $this->blu);

if ($this->transparent) ImageColorTransparent($image, $background);
ImageInterlace($image, false);

// render it.
ImageTTFText($image, $this->size, $this->rot, $offset_x+$this->pad, $offset_y+$this->pad, $foreground, $this->font, $this->msg);

// output PNG object.
imagePNG($image);
}
}

$text = new textPNG; // instantiate new textPNG class.

if (isset($msg)) $text->msg = $msg; // text to display
if (isset($font)) $text->font = $font; // font to use (include directory if needed).
if (isset($size)) $text->size = $size; // size in points
if (isset($rot)) $text->rot = $rot; // rotation
if (isset($pad)) $text->pad = $pad; // padding in pixels around text.
if (isset($tr)) $text->transparent = $tr; // transparency flag (boolean).
if (isset($clr)) { // text colour
$text->red = hexdec(substr($clr, 0, 2));
$text->grn = hexdec(substr($clr, 2, 2));
$text->blu = hexdec(substr($clr, 4, 2));
}
if (isset($bg)) { // background colour
$text->bg_red = hexdec(substr($bg, 0, 2));
$text->bg_grn = hexdec(substr($bg, 2, 2));
$text->bg_blu = hexdec(substr($bg, 4, 2));
}

// make up some expiry information. say, 60 secs to ive.
$now = mktime (date(“H”),date(“i”),date(“s”),date(“m”),date(“d”),date(“Y”));
$expires = mktime (date(“H”),date(“i”),date(“s”) + 60 ,date(“m”),date(“d”),date(“Y”)); // add 60 secs.
$expires_gmt = gmdate(‘D, d M Y H:i:s’, $expires).’ GMT’;
$last_modified_gmt = gmdate(‘D, d M Y H:i:s’, $now).’ GMT’;

header(‘Content-type:image/png’);
header(‘Expires: ‘.$expires_gmt);
header(‘last-modified: ‘.$last_modified_gmt);

$text->draw();
?>

PHP : Protect image in Xgallery

17 Mar

use .htaccess to protect other people from linking my images to their site. to protect gif and jpg I use this :

CODE

RewriteEngine onRewriteCond %{HTTP_REFERER} !^$RewriteCond %{HTTP_REFERER} !^http://(www.)?your_domain.com/.*$ [NC]RewriteRule .(gif|jpg)$ – [F]

Replace your_domain.com with your domain.

PHP : Image Gallery

17 Mar

<?php

/*

Created by Jeff Harrell
http://www.juxtadesign.com

Feel free to implement this however you want. However, if you
make any good changes then let me know and I will see about
incorporating them. Use at your own risk!

Just place PHP file in a folder that contains subfolders of images.
For formatting, the script will convert “_” characters in folder and
image names to spaces and title case the name. Make sure there are no
image files on the same level as the PHP script.

*/

/* CONFIGURABLE OPTIONS */

// page and breadcrumb prefix (okay to use html)
$title = ‘My Site | ‘;

// description (used in meta tags)
$description = ‘A collection of personal digital photos taken by you!’;

// the CSS is located in an external file named in the configuration below.
// if you would like to use the style sheet this was created with you may
// download it here:
// http://juxtadesign.com/photos/styles.css
$style_sheet = ‘styles.css’;

// allowed image extensions (separate by spaces)
$image_extensions = ‘jpg gif png’;

/* NO NEED TO CHANGE BELOW UNLESS YOU WANT TO */

// get the scripts info
$path = explode(‘/’,$_SERVER[‘SCRIPT_FILENAME’]);
$name = $path[(count($path) – 1)];
$folder = $path[(count($path) – 2)];
$show_directory = $_GET[‘directory’];
$show_image = $_GET[‘image’];
$keywords = ”;

function process() {
global $title, $path, $name, $folder, $show_directory, $show_image, $image_extensions;

// if url contains a directory go there
if ($show_directory) {
if (is_dir($show_directory)) {
chdir($show_directory);
} else {
// error directory does not exist!
header(‘Location: ‘ . $_SERVER[‘SCRIPT_NAME’]);
}
}

// now get the current directory
$cwd = getcwd();

// open directory
if ($handle = opendir($cwd)) {
// loop through all files adding files and directories to an array
while (false !== ($file = readdir($handle))) {
if (!preg_match(“/^\./”, $file)) {
$ext = explode(‘.’, $file);
$ext = $ext[count($ext) – 1];

if (is_dir($file)) {
$dirs[] = $file;
} else if (strpos($image_extensions, $ext) > -1) {
$files[] = $file;
}
}
}

// close directory
closedir($handle);

// process any files and folders found
processfolders($dirs);
processfiles($files, $dirs, $cwd);
}

return ob_get_contents();
}

function processfolders($dirs) {
// if directories exist sort and display them
if (is_array($dirs)) {

// output the page breadcrumb navigation
breadcrumb();

// sort the directories
natsort($dirs);
$dirs = array_values($dirs);

// output the directory listing
echo ‘<div class=”textlinks”>’;
foreach($dirs as $dir) {
echo ‘<a href=”‘ . $_SERVER[‘SCRIPT_NAME’] . ‘?directory=’ . $dir . ‘&image=0″ title=”‘ . formatname($dir) . ‘”> ‘ . formatname($dir) . ‘</a><br />’;
}
echo ‘</div>’;
}
}

function processfiles($files, $dirs, $cwd) {
global $title, $path, $name, $folder, $show_directory, $show_image, $keywords, $image_extensions;

// if no files exist then output some pictures
if (!is_array($files)) {
// open a random directory
srand((double) microtime() * 1000000);
$rand_dir = $dirs[rand(0,count($dirs)-1)];

if (is_dir($rand_dir)) {
chdir($rand_dir);

// open directory
if ($handle = opendir($cwd . ‘/’. $rand_dir)) {
// loop through all files
while (false !== ($file = readdir($handle))) {
// ignore hidden files and this file and add all else to an array
if (!preg_match(“/^\./”, $file)) {
$ext = explode(‘.’, $file);
$ext = $ext[count($ext) – 1];

if (!is_dir($file) AND strpos($image_extensions, $ext) > -1) {
$files[] = $file;
}
}
}
}
// close directory
closedir($handle);

// output multiple images in a block
echo ‘<div class=”imageblock”>’;
$x = 0;
while ($x < 4) {
// choose a random picture and get its heigh / width
// slightly buggy since it can sometimes add more than one of the same pic
$rand_pic = rand(0,count($files) – 1);
$image_info = getimagesize($files[$rand_pic]);
$image_width = $image_info[0];
$image_height = $image_info[1];

// if the picture format is landscape then use it
if ($image_width >= $image_height) {
echo ‘<a href=”‘ . $_SERVER[‘SCRIPT_NAME’] . ‘?directory=’ . $rand_dir . ‘&image=’ . $rand_pic . ‘” title=”‘ . formatname($files[$rand_pic]) . ‘”><img src=”‘ . $rand_dir . ‘/’ . $files[$rand_pic] . ‘” width=”160″ height=”120″ alt=”‘ . $files[$rand_pic] . ‘” /></a>’;
$x++;
}
}
echo ‘</div>’;
} else {
// output the page breadcrumb navigation
breadcrumb();

// output the directory listing
echo ‘<div class=”textlinks”>There are no files to display.</div>’;
}

// else if files exist in directory sort and display them
} else if (is_array($files)) {
// sort the files
natsort($files);
$files = array_values($files);

// url of image
// if none fix link color issue and redirect to image 0 (work around)
if (isset($show_image) AND is_file($files[$show_image])) {
$image = $files[$show_image];
} else {
header (‘Location: ‘ . $_SERVER[‘SCRIPT_NAME’] . ‘?directory=’ . $show_directory . ‘&image=0’);
}

// output the page breadcrumb navigation
breadcrumb();

// title of image
echo ‘<div class=”title”>’;
echo formatname($image);
echo ‘</div>’;

// image
if (file_exists($image)) {
$image_info = getimagesize($image);
$image_width = number_format($image_info[0]);
$image_height = number_format($image_info[1]);

echo ‘<div class=”photo”>’;
echo ‘<img src=”‘ . $_REQUEST[‘d
irectory’] . ‘/’ . $image . ‘” width=”‘ . $image_width . ‘” height=”‘ . $image_height . ‘” alt=”‘ . $image . ‘”>’;
echo ‘</div>’;
}

// next and previous links for the images
echo ‘<div class=”textlinks”>’;
if ($_REQUEST[‘image’] > 0) {
echo ‘<a href=”‘ . $_SERVER[‘SCRIPT_NAME’] . ‘?directory=’ . $_REQUEST[‘directory’] . ‘&image=’ . ($_REQUEST[‘image’] – 1) . ‘” title=”‘ . formatname($files[$_REQUEST[‘image’] – 1]) . ‘”>Previous</a>’;
} else {
echo ‘Previous’;
}

echo ‘ | ‘;

if ($_REQUEST[‘image’] < (count($files) – 1)) {
echo ‘<a href=”‘ . $_SERVER[‘SCRIPT_NAME’] . ‘?directory=’ . $_REQUEST[‘directory’] . ‘&image=’ . ($_REQUEST[‘image’] + 1) . ‘” title=”‘ . formatname($files[$_REQUEST[‘image’] + 1]) . ‘”>Next</a>’;
} else {
echo ‘Next’;
}
echo ‘</div>’;

// image links
// add image name to keywords variable
echo ‘<div class=”numberlinks”>’;
foreach($files as $file) {
$i++;
echo ‘<a href=”‘ . $_SERVER[‘SCRIPT_NAME’] . ‘?directory=’ . $_REQUEST[‘directory’] . ‘&image=’ . ($i – 1). ‘” title=”‘ . formatname($files[$i – 1]) . ‘”>’ . $i . ‘</a> ‘;
keywords($file);

}
echo ‘</div>’;
}
}

function formatname($string) {
global $image_extensions;

$string = ereg_replace(“_+”, ‘ ‘, $string);
$string = ereg_replace(“-+”, ‘ ‘, $string);
$string = ereg_replace(“\r+”, ‘ ‘, $string);
$string = ereg_replace(“\t+”, ‘ ‘, $string);
$string = ereg_replace(” +”, ‘ ‘, $string);

$image_extension = explode(‘ ‘, $image_extensions);
for($i=0;$i<count($image_extension);$i++) {
$string = str_replace(‘.’ . $image_extension[$i],”,$string);
}

$string = ucwords($string);
return $string;
}

function breadcrumb() {
global $title, $folder, $show_directory;

echo ‘<div class=”breadcrumb”>’;
if ($show_directory) {
echo $title .= ‘<a href=”‘ . $_SERVER[‘SCRIPT_NAME’] . ‘”>’ . formatname($folder) . ‘</a> | ‘ . formatname($show_directory);
} else {
echo $title .= formatname($folder);
}
echo ‘</div>’;
}

function keywords($string) {
global $keywords;

$words = formatname($string);
$words = explode(‘ ‘, $words);

foreach($words as $word) {
if (!empty($word)) {
if (strpos($keywords, $word) === false) {
$keywords .= $word . ‘, ‘;
}
}
}
}

// generate the photo html
ob_start();
$html = process();
ob_end_clean();

?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml&#8221; xml:lang=”en” lang=”en”>
<head>
<title><?php echo strip_tags($title); ?></title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<meta name=”description” content=”<?php echo $description; ?>” />
<meta name=”keywords” content=”<?php echo $keywords; ?>” />
<link rel=”stylesheet” type=”text/css” media=”screen” href=”<?php echo $style_sheet; ?>” />
</head>
<body>

<?php echo $html; ?>

</body>
</html>