Latest Posts



Single PHP error page to handle all response headers / errors

There might be an easier way of doing this but i’ve been working on a project which needed the following which i have done as a simple single php page and thought i’d share it in case anyone wants to do the same thing.

  1. Error page generated by dynamic pages
    (using any code; 403, 404 etc)
  2. Error page to handle genuine errors
    (404 ‘Not Found’, 403 ‘Forbidden’ etc)
  3. Forbid visitors from visiting sensitive areas/directories
    also returning 403 ‘forbidden’ header.
    (e.g. /images, /css /javascript, /ajax etc)

Download all these files: http-error-code.zip

instructions for use are commented within the error.php code but in summary:

You need to create a .htaccess entry for each error code:

Code for .htaccess:


ErrorDocument 403 /error/error.php
ErrorDocument 404 /error/error.php

For forbidden folders just add this code into a file called index.php then put this file into the folder that you want to forbid directory listing for:

Code for index.php:

<?php
// Set response code
$error = 403; //Forbidden
// include the error page (
include ($_SERVER['DOCUMENT_ROOT'].'/error/error.php'); // assuming "/error/error.php" is the location/name of this file
// stop processing the current page
exit();
?>

Save this code to a file called error.php and save to yourdomain.com/errors/error.php

Code for error.php:

<?php
/*
------------------------------------------
PHP Response Header / Error Page Generator
------------------------------------------
Created by Alan Hart (www.alanhart.co.uk)
19/09/2011
------------------------------------------

To generate response from another page, as a result of incorrect database query or invalid content etc just add this code:
(make sure no page output has been generated before this include)

<?php
// Set response code
$error = 403; //Forbidden
// include the error page (
include ($_SERVER['DOCUMENT_ROOT'].'/error/error.php'); // assuming "/error/error.php" is the location/name of this file
// stop processing the current page
exit();
?>

-------------------------------------------------------
TIP:
-------------------------------------------------------
Hide the default directory listing for a folder
e.g. /images, /css, /java etc.

1. create a blank file called index.php
2. paste the php code above into the file
3. place it inside the folder
-------------------------------------------------------
*/

// ------------------------------
// THE CODE...
// ------------------------------

// if the error code has been set by referring page:
if ($error <> ""){
// Use the error code from referring page
$code = $error;
} else {
// Use the error code from server
$code = $_SERVER['REDIRECT_STATUS'];
}

// set $path variable to the requested path/uri
$path = $_SERVER['REQUEST_URI'];

// Create array with error codes and messages
// You must add a line to .htaccess for each code used here.
// e.g.
// ErrorDocument 403 /error/error.php
// ErrorDocument 404 /error/error.php
// etc...
// (assuming /error/error.php is the location/name of this file)

// Common Error Codes / Responses:
$response['403'] = array('title' => '403 Forbidden', 'message' => 'The server has refused to fulfill your request.
You do not have permission to access '.$path.' on this server.');
$response['404'] = array('title' => '404 Not found', 'message' => 'The document/file requested was not found on this server.') ;
$response['405'] = array('title' => '405 Method Not Allowed', 'message' => 'The method specified in the Request-Line is not allowed for the specified resource.') ;
$response['408'] = array('title' => '408 Request Timeout', 'message' => 'Your browser failed to send a request in the time allowed by the server.') ;
$response['500'] = array('title' => '500 Internal Server Error', 'message' => 'The request was unsuccessful due to an unexpected condition encountered by the server.') ;
$response['502'] = array('title' => '502 Bad Gateway', 'message' => 'The server received an invalid response from the upstream server while trying to fulfill the request.') ;
$response['504'] = array('title' => '504 Gateway Timeout', 'message' => 'The upstream server failed to send a request in the time allowed by the server.') ;

// Other header response codes (not necessarily errors) that you may want to use:
// $response['100'] = array('title' => '100 Continue', 'message' => 'Continue')
// $response['101'] = array('title' => '101 Switching Protocols', 'message' => 'Switching Protocols')
// $response['200'] = array('title' => '200 OK', 'message' => 'OK') // *Not an error so should never be handled by this script*
// $response['201'] = array('title' => '201 Created', 'message' => 'Created')
// $response['202'] = array('title' => '202 Accepted', 'message' => 'Accepted')
// $response['203'] = array('title' => '203 Non-Authoritative Information', 'message' => 'Non-Authoritative Information')
// $response['204'] = array('title' => '204 No Content', 'message' => 'No Content')
// $response['205'] = array('title' => '205 Reset Content', 'message' => 'Reset Content')
// $response['206'] = array('title' => '206 Partial Content', 'message' => 'Partial Content')
// $response['300'] = array('title' => '300 Multiple Choices', 'message' => 'Multiple Choices')
// $response['301'] = array('title' => '301 Moved Permanently', 'message' => 'Moved Permanently') // *Not an error so should never be handled by this script*
// $response['302'] = array('title' => '302 Found', 'message' => 'Found')
// $response['303'] = array('title' => '303 See Other', 'message' => 'See Other')
// $response['304'] = array('title' => '304 Not Modified', 'message' => 'Not Modified')
// $response['305'] = array('title' => '305 Use Proxy', 'message' => 'Use Proxy')
// $response['307'] = array('title' => '307 Temporary Redirect', 'message' => 'Temporary Redirect') // *Not an error so should never be handled by this script*
// $response['400'] = array('title' => '400 Bad Request', 'message' => 'Bad Request')
// $response['401'] = array('title' => '401 Unauthorized', 'message' => 'Unauthorized')
// $response['402'] = array('title' => '402 Payment Required', 'message' => 'Payment Required')
// $response['406'] = array('title' => '406 Not Acceptable', 'message' => 'Not Acceptable')
// $response['407'] = array('title' => '407 Proxy Authentication Required', 'message' => 'Proxy Authentication Required')
// $response['409'] = array('title' => '409 Conflict', 'message' => 'Conflict')
// $response['410'] = array('title' => '410 Gone', 'message' => 'Gone')
// $response['411'] = array('title' => '411 Length Required', 'message' => 'Length Required')
// $response['412'] = array('title' => '412 Precondition Failed', 'message' => 'Precondition Failed')
// $response['413'] = array('title' => '413 Request Entity Too Large', 'message' => 'Request Entity Too Large')
// $response['414'] = array('title' => '414 Request-URI Too Large', 'message' => 'Request-URI Too Large')
// $response['415'] = array('title' => '415 Unsupported Media Type', 'message' => 'Unsupported Media Type')
// $response['416'] = array('title' => '416 Requested range not satisfiable', 'message' => 'Requested range not satisfiable')
// $response['417'] = array('title' => '417 Expectation Failed', 'message' => 'Expectation Failed')
// $response['418'] = array('title' => '418 I\'m a teapot', 'message' => '(RFC 2324) Hyper Text Coffee Pot Control Protocol')
// $response['501'] = array('title' => '501 Not Implemented', 'message' => 'Not Implemented')
// $response['503'] = array('title' => '503 Service Unavailable', 'message' => 'Service Unavailable')

// get the relevant title from array
$title = $response[$status]['title'];

// get the relevant message from array
$message = $response[$status]['message'];

// return message if error code provided isn't in the $codes array
if ($title == false || strlen($code) != 3) {
$message = 'Please supply a valid status code.';
}
// Return response header(s) with relevant code
header("HTTP/1.1 ".$title);

// Customise the page to be displayed below...

// -------------------------------------------------------
// You can use the variables $title and $message in the page
// -------------------------------------------------------
// e.g.
//        echo "<h2>".$title."</h2><p>".$message."</p>";
// -------------------------------------------------------

// -------------------------------------------------------
// !! IMPORTANT !!
// -------------------------------------------------------
// if you want to include a header / footer in the page displayed
// make sure you use $_SERVER['DOCUMENT_ROOT'] in your include code
// e.g.
//         include($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
//
// this ensures the header/footer path is always correct
// e.g.
//        actual path of header.php = "http://www.domain.com/inc/header.php"
//         if path/uri is "domain.com/foo/" header path would incorrectly become "domain.com/foo/inc/header.php"
//        if path/uri is "domain.com/foo/bar/" header path would incorrectly become "domain.com/foo/bar/inc/header.php"
// -------------------------------------------------------

?>
<?php
// Include your own header here
//         include($_SERVER['DOCUMENT_ROOT']."/inc/header.php");
// or use HTML as below
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Error: <?php print $title;?></title>
</head>
<body>
<center>
<?php echo '<h2>'.$title.'</h2><p>'.$message.'</p>'; ?>
</center>
<?php
// Include your own footer here
//         include($_SERVER['DOCUMENT_ROOT']."/inc/footer.php");
// or use HTML as below
?>
</body>
</html>

 


Pay off a mortgage in a year?

I have had a crazy idea to see if the combined generosity of complete strangers can help pay off our mortgage.

It might be a stupid idea and i’m guessing won’t even get a single donation, but maybe i’ll be proved wrong. If you dont ask you don’t get. right?

To donate please go to http://alanhart.chipin.com
All we need is just 160,000 people to donate 63p ($1)

If this does take off i’m hoping my blog will get a significant amount of visits so, because i’m such a nice guy, as a thank you (or incentive) for donating larger sums…

Every donation of $1 – $4.99…
will get a mention in a daily blog post

Every donation of $5 – $24.99…
will get a mention in a daily blog post with link to twitter or facebook profile

donations of $25 – $99.99…
will get a blog post on this website with link back to a website of your choice*

donations of $100 or more …
will get a blog post on this website with link back to a website of your choice*
AND
a link* in the links section in the sidebar (appears on every page of this site)

If you’re reading this please donate, remember all we need is just 160,000 people to donate 63p ($1)

*no illegal stuff please

connection to the server was reset in Hotmail, Firefox

Been having trouble logging into hotmail the last few days, after entering username and password, just get an error saying:

“The connection to the server was reset while the page was loading”

To clear this and actually log on to your hotmail just do the following:

if you have the “Web Developer Toolbar” plugin:
Click Miscellaneous > Clear Private Data > HTTP Authentication

If you don’t have the plugin:

  1. When in Firefox hold down:
    Ctrl + Shift + Del together
  2. Tick “Active Logins
  3. Click “Clear Now” button

Try and log into hotmail again and it will let you in, at last!

Google’s New Sitelinks

Sitelinks have been around for a while but used to look like this:
Old Style Sitelinks

Now they look like this!:
New Google Sitelinks for Microsoft
Within Google’s new search hierarchy, sitelinks will now be full-size links with a URL and a line of snippet text, similar to regular search results. But Google has also designated a maximum number of 12 sitelinks per search result, giving pride of place within the page to the first search result.

The changes will roll out globally to all modern browsers, including Chrome, Firefox, and Internet Explorer 7 and above, Google said.

Sitelinks are useful to users as they may not be able to specifically identify where in a site they want to visit, so he or she merely types in the overarching domain.

“It turns out that sitelinks are quite useful because they can help predict which sections of the site you want to visit,” Daniel Rocha, a software engineer on the Google Sitelinks team, wrote in a blog post. “Even if you didn’t specify your task in the query, sitelinks help you quickly navigate to the most relevant part of the site, which is particularly handy for large and complex websites. Sitelinks can also give you a good overview of a website’s content, and let webmasters expose areas of the site that visitors may not know about.”

Google has also said that it is tweaking its search algorithm to accommodate the changes. “In addition, we’re making a significant improvement to our algorithms by combining sitelink ranking with regular result ranking to yield a higher-quality list of links,” Rocha said. “This reduces link duplication and creates a better organized search results page. Now, all results from the top-ranked site will be nested within the first result as sitelinks, and all results from other sites will appear below them.”

Facebook enable dislike button wall post scam

Another facebook scam:

Users will see a wall post, supposedly from a friend.

The wall post says:

Facebook now has a dislike button! Click ‘Enable Dislike Button’ to turn on the new feature!”

facebook enable dislike button wall post

This is quite clever and looks exactly like it might be a genuine add-on, the “Enable Dislike Button” link appears exactly where the “Share” button appears on regular posts.

If you click on the link, the same wall post will be posted to all your friends’ walls, meaning that more and more people will be tricked the same way.

This is a scam. No “Dislike” button will be added anywhere.

Many Facebook users have been suggesting for quite a while now that facebook have a “Dislike” button so this scam is probably going to fool quite a few people people.

Please let everyone know about this “enable dislike button” scam and ensure your friends understand that they should be cautious of posts like this put on their walls, even from if they come from their own friends!

If you, or anyone you know, has this message posted on their wall, you can either hide it or mark it as spam. If you mark it as spam it helps Facebook to hopefully become aware of and remove this rogue application.

Access registry on another external hard drive

If you need to open a windows registry hive from an old/external/slave hard drive that has a windows installation on it.

I recently had a machine go down at work, wanted to get the user’s email up and running asap so i attached their hard dirve to my laptop using a usb to SATA adapter and exported their outlook account settings, which are stored in the registry and imported them into a new pc.
See my article: how to backup outlook 2007 account settings.

1. Open REGEDIT
2. single click to hightlight the HKEY_LOCAL_MACHINE branch.
3. in the menu click FILE and choose LOAD HIVE
4. browse to the location of the old registry hive.

where “x:\” is the drive of the slave/external hard drive…

“user” is located in x:\docs and Settings\user\NTUSER.DAT
make sure you open upper case “NTUSER.DAT” and not “ntuser.dat” if it exists.

other registry hives are located at x:\windows\system32\config

if you’re not sure or unclear on any of this, please comment and ask.

Updated: Facebook chat emoticons, emotes and smilies / icons

Related articles:
Change Facebook news feed to give it the old facebook look
Facebook chat emoticons, emotes and smilies / icons

Want to add smilies to your Facebook chat conversations?

Here are the obvious (and maybe less obvious) smilies / emoticons / emotes that you can send to your friends in Facebook chat!

Simply type what’s next to the smiley and it’ll show up when u send it to your friends in Facebook chat!

smile = :-) or :) or :] or =)

frown = :-( or :( or :[ or =(

tongue = :-P or :P or :-p or :p or =P

grin = :-D or :D or =D

gasp = :-O or :O or :-o or :o

wink = ;-) or ;)

glasses = 8-) or 8) or B-) or B)

sunglasses = 8-| or 8| or B-| or B|

grumpy = >:( or >:-(

unsure = :/ or :-/ or :\ or :-\

cry = :'(

devil = 3:) or 3:-)

angel = O:) or O:-)

kiss = :-* or :*

heart = <3

kiki = ^_^

squint = -_-

confused = o.O or O.o

upset = >:O or >:-O or >:o or >:-o

pacman = :v

Facebook Curly Lips Smily / Emote curly lips = :3

facebook robot emoticon robot = :|]

facebook Chris Putnam emoticon Chris Putnam = :putnam:

facebook shark emoticon Shark = (^^^)

penguin facebook emoticon Penguin = <(“)

NEW!

42 emote = :42:

You can also change the text style:

Bold Text Bold Text = *Bold Text*

Underlined Text Underlined Text = _Underlined Text_

Bold & Underlined Text Bold Text = *_Bold and Underlined Text_*

This is a list of all currently known Facebook chat emoticons.
I’m sure Facebook will be adding more emoticons in the future and when they do i’ll update this post.

Shutdown windows 7 without installing updates

There have been loads of times when updates are ready but i want the computer / laptop off and ready to move asap (to go home from work and take my laptop with me). was so annoying having to wait for windows to update when i didn’t want to.

I have found a way to shutdown windows 7 without being forced to install the updates…

Run regedit (search in start menu)

Under HKEY_LOCAL_MACHINE\Software\Policies\Microsoft\Windows\WindowsUpdate\AU
if the keys “WindowsUpdate” and “AU” aren’t there just add them (right click > New > Key)
right click > New > DWORD
name it “NoAUAsDefaultShutdownOption” double click it and enter value 1.

the “shutdown” button will never be changed by Windows Update from your default action to “shutdown and install updates”.
If updates are ready to be installed “shutdown and install updates” is instead displayed in the [>] menu to the side of the shutdown button

On my system it happend almost as soon as the registry value was added, but you may need to reboot before the change is applied.

Also important is “NoAutoRebootWithLoggedOnUsers”, also a DWORD in the same location with value 1. This stops Windows from rebooting automatically if a user is logged in or you leave it working overnight for example.

Compare CSS Stylesheet Tool

CSS is a standard used to define Web site presentation styles.
When a Web designer creates a CSS stylesheet for a site, he will evolve it through multiple versions with incremental changes.

This tool provides a solution that allows a web designer to clearly see the differences between two different css stylesheet files (classes only, not values)

Compare CSS Stylesheets

Description
A webpage that takes two CSS files and compares the classes contained in both. Resulting differences are highlighted in red.

Usage:
Click the “Compare CSS Tool” link below and simply upload the css files you want to compare and click the compare button.

Compare CSS Tool

Recent Posts