incorrect-captcha-sol recaptcha

I was pulling my hair out regarding this one for ages with the php version of recaptcha

I had everything in the right place, recaptchalib.php included, public private keys set, recaptcha_get_html inside the form. It should have worked.  See code below:

<html>
<head></head>
<body>
<?php
    require_once('recaptchalib.php');              
    $publickey="6LfBHssSAAAAAPxAqPSkddCIXcFIdrl2lrNxJ8da";
    $privatekey="6LfBHssSAAAAACIz-CYPmFpm6sp81S-W-RXingPz";
    $resp = recaptcha_check_answer ($privatekey,
                                    $_SERVER["REMOTE_ADDR"],
                                    $_POST["recaptcha_challenge_field"],
                                    $_POST["recaptcha_response_field"]);
    if ($resp->is_valid)
    {
        echo "Thank you ";
    }
    else
    {
        echo "Invalid recaptcha response: " . $resp->error;            
    }
?>
<table border="0" width="400" align="center">
    <form method="POST" action="">
        <tr><td>Name: </td><td><input type="text" name="name"/></td></tr>
        <tr><td>&nbsp</td><td><?php echo recaptcha_get_html($publickey, null);?></td></tr>
        <tr><td>&nbsp</td><td><input type="submit" value="submit" name="submit"></td></tr>            
    </form>    
</table>
</body>
</html>

When I submitted the form, no matter whether the code was correct or not I kept getting back incorrect-captcha-sol in $resp->error

Turned out in the end that the problem was very simple… I had the table tags outside the form tags instead of the other way around i.e.

<table> <form> <tr><td></td></tr> </form> </table> 

instead of:

<form> <table> <tr><td></td></tr> </table> </form> 

Once I changed to the latter, it began working fine.

Hope this helps someone out there!

Add Spam Protection to a Web Form

Often when submitting to websites you will see that nasty little thing that you have to type two words into to get the form to submit.  These nasty little things may save you receiving a lot of junk requests.

The industry standard as used by Facebook and Google is a technology called recaptcha which can be added to an existing form fairly easily by your web developer.

Here are the steps involved:

  1. Register your website with recaptcha and get public private keys here https://www.google.com/recaptcha/admin/create
  2. Download the software library (here is the php recaptcha link)
  3. Within your web form include the recaptchalib.php file
  4. Echo the function recaptcha_get_html(‘your public key’) within your web form
  5. Put in checks to determine if the code is valid

Here is a simple example:

<html>
<head></head>
<body>
<?php
require_once('recaptchalib.php');
$publickey = "your public key";
$privatekey = "your private key";

$resp = recaptcha_check_answer ($privatekey,
                                    $_SERVER["REMOTE_ADDR"],
                                    $_POST["recaptcha_challenge_field"],
                                    $_POST["recaptcha_response_field"]);

if ($resp->is_valid)
{
    echo "Success";
}
else
{
    echo "Failure";
}
?>
    <form method="post" action="">
<?php echo recaptcha_get_html($publickey, null); ?>
    <input type="submit" value="submit" name="submit" />
    </form>
</body>
</html>

And that’s it, just be sure to call recaptcha_get_html within your form.

 

Prestashop – No Search Results

So you’ve built your amazing prestashop and you’ve imported hundreds of products into the system but alas, when you peform a search, nothing is returned even though you know you’ve entered text present in one of your products.

This one had me stumped for a bit as I assumed that the data would be stored within the system or that prestashop would do some dynamic search on the database records. It turns out prestashop is a little more sophisticated than that and actually indexes all the products in the site to make search results quicker.

To ensure all of your products are indexed go to your backend, click on preferences and then search.

Once in there you will see how many products have been indexed. If you had the same problem as me you will see that 0 products have been indexed. This is because I imported products from a CSV. Manually inserted products are automatically indexed.

Once you are in backoffice->preferences->search you will see something like

Indexed products: 44 / 44.
-> Add missing products to index.
-> Re-build entire index.

You can click either option to re-index your products. Once you don’t have thousands of entries it should take < 1 min to do. You can also set up a cron job to perform this indexing regularly for you.

Other options on this screen inclued

  • Ajax search: To automatically fill in your search box, like google
  • Minimum word length
  • Blacklisted words

There are also options here to weight your search results using various factors such as weight, tags etc.

WordPress White Screen of Death (wp-admin blank screen problem)

If anyone out there is experiencing the WordPress white screen of death i.e. when you go to your wordpress wp-admin folder all you see is a blank screen, you may have been hacked.

I had a nasty little hack where link code was being injected into the footer of every rendered page. It was difficult to find as the links that were being injected were injected by an encoded script that had infected several files (especially in my themes folder). I went through each file and deleted the script from them. In this case, if you’re not experienced with code you would be safer to do a full re-install of your blog.

The result of the clean up was that several files had spaces injected into them at the top and bottom of the page. I did a full re-install to restore all the important files in the system and I still was experiencing the blank screen. Obviously wp-config.php wasn’t part of the update and so I cleaned out a blank line on the top of this module and I could finally log back in again.

Hope this helps someone out there.

Note: If you have been hacked, change all of your passwords, database, ftp, wordpress etc. and make sure that all file permissions on your server are set up correctly, be pessimistic.

Top 5 SEO Tips for 2011

Here are my top 5 SEO tips for 2011.

  1. Get a Clear Picture: The very first thing anyone performing SEO should do is get a clear picture of the current situation. The best way to do this is by installing Google Analytics.  After running Analytics for a month you will see some patterns emerging and you can determine how much traffic is coming from search engines.
  2. Filter out seasonal trends: There’s no way you can identify gains and losses unless you figure out the seasonal trends.  You can use a tool such as google trends to do this if you do not have your own data.
  3. Find Opportunities: As with any marketing exercise you need to determine if there is a market.  You need to identify the key phrases that people will use to find your site, but there’s no point in doing this if there is huge competition.  Find the best keyphrase volume you can that has poor returns on the search results page and target that.
  4. Apply Research Effectively: Once you have the keyphrases identified using tip 3, apply the keyphrase to your site naturally in key areas such as titles, headings, links and body text. Don’t over do it. Find out how many times your competitors use it. As always it is no harm to build links to pages.
  5. Measure Results: Using analytics, measure how many hits these keyphrases are generating for you as a percentage against your search engine results position. Tweak your page slightly each month to see if it positively or negatively affects your position. Link building may also affect your position positive and should be an ongoing task.

That’s it.  The basics are simple enough, do them right and you can’t go too far wrong.  It’s that final 20% that’s the most painstaking and most difficult.  Keep at it and you will get ahead of most of your competitors within a realistic time frame.

Putting Euro Symbol in Inner Text HTML using Javascript

Had a problem today whereby I tried to insert a euro symbol into the innertext of a div using javascript.

First I tried the actual euro symbol

e.g.

document.getElementById('theelementid').innerText ="€" + value;

This results in the user agent outputting an unrecognised symbol in place of the euro

Then I tried using the html escape code for the euro symbol:

i.e.

document.getElementById('theelementid').innerText ="&euro;" + value;

But that resulted in the &euro; being displayed verbatim by the browser as the DOM automatically encodes special characters such as the ampersand

Finally, I actually escaped it using the unicode value

i.e.

document.getElementById('theelementid').innerText ="\u20AC" + value;

and it worked like a treat.

:-)

http://www.thejesusalien.com/michael-jackson-is-not-dead-hes-an-ancient-egyptian-princess/

Centering a Website – Cross Browser

Most sites these days are centred and have a fixed with be it 800, 1024 pixels wide or whatever.  If any of you have used divs and css and tried using standard centering you might have, at one stage or another, scratched your head while viewing it on different browsers.

Let’s say we want a webpage with a width of a nice round 1000 pixels. To do this we might create a new div within the body tag called page:

<body>
<div class="page">Content goes here<br/><br/><br/><br/><br/></div>
</body>

In order to centre this on IE7 and less we simply set the width in the div and in the body tag set text-align to center i.e.

body
{
 text-align: center;
}
.page
{
 width: 1000px;
 text-align: center; /*don't forget to reset alignment for child elements*/

}

On IE8+, Firefox and other browsers this is not correct behaviour however and they will left align the inner div, therefore we need to centre the inner div using the margin tag by setting it to margin: 0 auto e.g.

body
{
 text-align: center;

}
.page
{
 margin: 0 auto;
 text-align: left;
 width: 1000px;
 background-color:red;

}

By specifiying margin: 0 auto and by setting the div’s width, the browser can calculate how much distance to place between the left side of the div and the left margin of the browser window.

So there you have it, simple and effective and cross browser compatible.

Flash Caching Issue on IE

I had a problem with a client of a client whereby they had a flash gallery component called simpleviewer on the site.  Basically depending on the page the browser viewed, the component would load up a dynamic xml file and present a different slideshow on each page.

The problem happened when users have caching turned to automatic.

I tried various things like, setting the various meta tags for browser caching in the head section of the html document

<META HTTP-EQUIV="Expires" CONTENT="0">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">

I tried setting this in the footer also because of IEs caching problem.

I then tried setting this sort of stuff on the server through php headers even setting the last modified date:

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header ("Last-Modified: " . gmdate ("D, d M Y H:i:s") . " GMT");

I then tried setting parameters on the .swf file itself hoping that it would see it as a new request for a different swf file each time (where contentid is the id of the page loading).

var fo = new SWFObject("viewer.swf?unique=<?php echo $contentid ?>",
"viewer", "640", "380", "8", "#ffffff");

In the end i figured out that the flash file itself was caching the xml document that it was loading  so this had to be different for each page request (I had been using cookies to store the currently selected page). 

fo.addVariable("xmlDataPath",
"gallery.php?contentid=<?php echo $contentid ?>");

And low and behold, problem solved.

Talk about beating about the bush!

Anyway, hope this helps someone else out there.

Double Home Page Problem WordPress

Many of us WordPress users will have come up with the double Home Page problem.

If you are using WordPress to create a website often you want a static home page on the site and not have it default to the latest blog entry.  To do this you must log in to the admin area, go to setttings->reading and set a static page as your homepage.

Often times you will want to create this page and title it ‘Home’ however on most themes if you do this you will end up with two home pages.

To get around this, without editing the theme, you need to create a dummy static page that is hidden from public view.  Once this static page is created you must go back and edit the newly created home page and set its parent to this new dummy page.

And that should be it!

If you want to have your blogs appear on another page, simply create another static page (with no content) and again go to settings->reading and set the posts page to this page. You must do this before you make the dummy page private, however.

Changing Domains and 301 Redirects

If you want to move your business to a new domain and you have a popular domain name with a decent Google Page rank you will most certainly want to redirect traffic from your old website to your new website.

There are many ways to do this. Some of the most popular are:

  • using meta tags: this is a client side method that redirects the browser after a certain amount of time
  • using a server side script: this could be a simple .php that redirects users from a page (generally homepage) to your new site
  • use a .htaccess file and a rule to redirect traffic to your new site

META REFRESH REDIRECT

The meta refresh mechanism is quite simple, you insert code like this into the header of the page you wish to redirect:

<META http-equiv=”refresh” content=”5;URL=http://www.yournewsite.com/”>

This will redirect to your new site 5 seconds after the page loads on the viewer’s browser.  This method is simple and require no server side scripting knowledge.

PHP 301 REDIRECT

With languages like php you can use the header function to redirect to other pages. Here is an example of how to perform a 301 redirect with php.

<?php
header( “HTTP/1.1 301 Moved Permanently” );
header(‘Location: http://www.yournewsite.ie/’);
?>

NOTE: this code must appear at the top of the .php file as if the script echoes anything at all to the client the redirect will not work.

This method is good as it performs a proper 301 redirect so that your new site picks up all of the page rank associated with the old page, the only disadvantage here is that it must be done page by page.

This 301 has been tried and tested on http://www.utdwebdesign.com and redirects to http://www.utdwebdesignireland.com

.HTACCESS 301 REDIRECT

This is the preferred method of performing a 301 redirect for all pages of a site but only works on Linux hosting. Here is an example of a .htaccess file with a 301 redirect rule for all pages of a website:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^yournewsite.com$ [NC]
RewriteRule ^(.*)$ http://www.yournewsite.com/ [L,R=301]

This .htaccess 301 Redirect has been tried and tested on Godaddy hosting for the website http://www.barrackstreetconcertband.com and redirects the user to http://www.barrackstreetband.com