Skip to main content

Posts

Auto-responder

This is an email auto-responder script.   The instructions for use are in the comments at the top of the script.   The script is intended to be run using Cron at preset invervals (for example every hour).   The script should be placed above the public directory to provide better security and to ensure no one else runs the script from http.

- - Start Script Here - -
<?php/*
Email auto-responder script.  Save in a file named responder.php
The script reads an IMAP mail box and auto-responds to all emails where the to address matches an address in the addressMatch array.
All messages checked by the script are marked as read and the script will only respond to unread messages.  This prevents duplicate responses.
Optionally, can set a flag to only send one response per received email address.
  -> Controlled by entries in the responder.dat file, which the script will create for you.
  -> To reset to send everyone a response again, simply delete the responder.dat file.
You must review and ch…

Setting up SPF Records

SPF records are used to help ensure that no one sends emails claiming to be from you when they are not (called spoofing).   The receiving mail server checks the SPF record for the domain sending the mail.   The SPF record identifies all the valid servers that can send mail for that domain.   If the mail is from a server not listed, then the mail is rejected.   If there is no SPF record for a domain, then there is no check.

To create an SPF record you must add a TXT recrod to your DNS.   In your DNS text record, the first field should be:
YourDomainName.com.
note - the trailing period is required

The value field should be:
"v=spf1 a mx ~all"
note - the quotation markes are required

So your SPF record in your DNS looks like this:
YourDomainName.com. IN TXT "v=spf1 a mx ~all"

This SPF record means that only your web server (a) and your mail (MX) server can send mail for YourDomainName.com

Please understand that this will only work if ALL your mail is sent from your webhost usin…

Resize Images (create thumbnails)

This script will take any image and automatically create a thumbnail of any size you want.   The instructions for using this script are in the comment lines at the top of the script.

- - Start Script Here - -
<?// this script creates a thumbnail image from an image file - can be a .jpg .gif or .png file
// where $thumbsize is the maximum width or height of the resized thumbnail image
// where this script is named resize.php
// call this script with an image tag
// <img src="resize.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg$thumbsize = 200;$imagesource =  $_GET['path'];$filetype = substr($imagesource,strlen($imagesource)-4,4);$filetype = strtolower($filetype);
if($filetype == ".gif")  $image = @imagecreatefromgif($imagesource);
if($filetype == ".jpg")  $image = @imagecreatefromjpeg($imagesource);
if($filetype == ".png")  $image = @imagecreatefrompng($imagesource);
if (!$image) die();$imagewidth = imag…

Random/weighted banners, quotes & more

This script will display banners (with or without links), quotes, or anything else you want to randomly select with each individual page load.   The item will be randomly selected, but the frequency of selection can be weighted based on a value you specify.   For example, giving an item a weight of 2 will cause that item to be selected twice as often as an item with a weight of 1.   Use only integers 1 or greater for weight values.

You can specify the item as html code in the script, or have each item be stored in an external file (also as html code).   The switch at the top of the script makes the selection of in-script or external files.   The example below shows the in-script method.

- - Start Script Here - -
<?php
$externalFile = "N";  // Y means the item array contains file names
// add to the weight and item arrays below$weight[0] = 1; $item[0] = "<a href='link0.htm'><img src='image0.gif'></a>";$weight[1] = 1; $item[1] = "…

Ensure your page is not opened in a frame

If you want to make sure your website is not opened in a frame from some other website, put this JavaScript in the <head> of your html page:

<script type="text/javascript">
if (top.location != self.location) { top.location.href = self.location.href; }
</script>

Stop direct links to web pages Want to stop someone from entering your site unless they come in the "front door"?  Or want to keep a frame page from being loaded outside of the frameset?  This script example will not let you load page2 unless you have already loaded page1 in the same browser session.

Note that if someone loads page1 they can then go directly to page2 anytime in the SAME browser session.  But if they close the browser, then next time they must again enter through the "front door".

page1.php has this script:

<?php
session_start();$_SESSION['valid'] = "yes";
echo "Page 1";?>
page2.php has this script:

<?php
session_start();
if ($_SESSION['…

Sticky default values for an input

Using this example JavaScript you can have a password entry field that contains the text "Enter Password".  The text will go away when the user enters data.  But if the leave the field blank it will go back to "Enter Password".  This can be modified for use with any input field.  Put the JavaScript below in the <head> section of your html page.

<script type="text/javascript">
function focus(el) {
  if (el.defaultValue==el.value) el.value = ""
}
function blur(el) {
  if (el.value == "") el.value = el.defaultValue;
}
</script>

The <input> tag looks like the one below.  Note the onFocus and onBlur function calls.

<input type=text style="width: 120;" value="Enter Password"
onFocus="focus(this)" onBlur="blur(this)" name=password maxlength=10 autocomplete=off>

Moving (bouncing) Image You can have a moving (or bouncing) image on your web page.  A great idea for a logo.  Click this link…

Copying the php.ini file

You can find another Tip on this page for how to create a custom php.ini file.  But after you create it, many hosts will require you to put a copy in each directory.  This script makes it easy.  It will copy the php.ini file from your main public directory and put one in all the subdirectories.  If you do not want it in every subdirectory, after you delete the ones you do not want you can do all future updates with the overwriteOnly flag on.

- - Start Script Here - -
<?php// set this value to Y if you only want to overwrite old php.ini files
// set this value to N if you want to put a php.ini file in every directory$overwriteOnly = "Y";

if ($overwriteOnly == "Y") echo "Operating in Overwrite Only Mode<br><br>";$path = "/home/" . get_current_user() . "/public_html";$source = $path . "/php.ini";
if (!file_exists($source)) die('Error - no source php.ini file');
function search($dir) {
  global $source;
  global $o…