June 10th, 2007
Whenever I want to display a table of financial values - I like all the figures to line up, and also to have the currency symbol line up neatly too.
I use the PHP function pad_str to pad spaces to the right of the monetary value, but the problem is that HTML then interprets all the consecutive spaces as a single space. You have to use a non-breaking space with the PHP pad_str, and you do it like this, using str_replace help out when str_pad can’t cope with :
$space = chr(0xA0);
str_replace(" ", " ", str_pad($price,8, " ", STR_PAD_LEFT))
CSS
td.money{
text-align: right;
font-family: Courier New, Fixedsys;
}
Sphere It
Leave Comment » | Posted in Web Development
April 28th, 2007
A few months ago some of my sites became victims of form spam. This is where you have a form on your web site - one that perhaps allows visitors to make an enquiry, and then one day you realise that hundreds of people are receiving spam emails from you and your domain. And there is nothing you can do to prove it was not really you that sent the spam. This means that when you do send out an email it may be rejected because your email address has been added to some blacklist or other.
Another way you might find out about it, is that you get several emails from forms on your web site that rather than be from genuine site visitors, are full of rubbish, or contain inane comments like “nice site” and nothing else.
You can’t tackle form spam all that easily as I guess the spammers will think of a way around it. Hell - I am sure they read all the posts like this one that explain to people how to prevent it, and then make their workarounds.
How form spam is done is explained elsewhere on the internet - but suffice to say, the spammers can take two routes.
- Hire cheap labour to fill in forms on websites around the web containing advertising, lists of links to medical supply sites etc. This is just annoying, but need not be too dangerous.
- Write programs to automatically submit to the processing page of your form - bypassing the physical form filling altogether. This is much more dangerous as any javascript validation, or form based validation (e.g. maxlength on an input field) you are doing is completely irrelevant. This means they can post values into your post variables directly, and if you are not doing server side validation, they can inject any of these variables with values that confuse the sendmail function that you eventually call to send what you thought was the form contents as an email to yourself into sending thousands of spam emails to his list of victims instead.
Here are a list of simple preventative measures you can take in your server side validation processing.
- Limit the size of the post variable values. On the form you said the input field in question was say limited to 50 characters. But this spammer person didn’t use your form - he skipped straight to your processing page, so the 50 character limit was useless in this context. Make sure you see this through to the server side and if there are more than 50 (or whatever limit you have placed) characters in the variable - you know your form has been hijacked.
- Place a field on your form with a name like subject or more_information, but use CSS to display:none to make it invisible. Don’t do this directly, but use some CSS in an external file to set the field up to to not display. Spammers can’t resist a wide open field and will probably fill it in. During your server side processing, if you see this field has any value at all, you know its been spammed.
- Validate any email address field using a regular expression. You’ll find an email regular expression
here that works quite well. Validating for an email address is preferable to checking all email address fields to check they don’t contain linefeeds and bcc: and other spam like characters. If the field fails email validation, you probably have a spammer.
- Send out emails as usual for all the forms that get through your checks
- Don’t send anything for any form that does not get through your checks. Write the contents to a file on your server with a datestamp for the file name, and then send yourself an email with the value of the filename you generated in it.
Sphere It
2 Comments » | Posted in Web Development
April 27th, 2007
getgoogleadsfree.com is the web address of a site that sells an ebook. Ads for this site seem to be everywhere, and in case you are wondering how it is possible to get adwords for free I can tell you here, and you can decide if you want to go to the web site and buy the ebook.
The way the author achieves it is by showing you how to put paid ads on your site that will earn you enough money so that you can use this advertising revenue to pay for the adwords clicks you need for yourself.
So you are not getting adwords for no cost, or for free - you are in fact off-setting the cost of your adwords campaigns by earning enough to pay for them. Now that is not a bad idea, and the ebook may well give you really good tips on how to achieve this, but I think it is a bit misleading to imply in several points in the copy that the ads themselves are for free. After all, that is like saying food in the supermarket is for free because you pay for it by earning money elsewhere. OK. Blimey - maybe I have a future in this after all?
That said, I was brought up (rightly or wrongly) not to expect anything for free - so maybe that is why the advertising for this product irked me so much. At the time of writing the web site contained these words :
You CAN now bid as high as you like on any select keyword (and thereby blow ALL your competition right out of the water! — and NEVER have to pay for a single ‘click!’)
and
You CAN now set your daily budget as high as you want to go (and thereby be assured of having ONLY the BEST *TOP PREMIUM* positions at all Search Engines — these are the color ribbon areas over the “organic” results everybody sees first!) But DON’T worry as you’ll never pay for a single day of pay-per-click advertising regardless of how high you set your budget!
I wouldn’t be surprised if the copy on that site changes in the next few weeks. It is beyond the pale - despite the disclaimers.
Why do marketers resort to this sort of sensationalist copy? I guess it is because a lot of people are attracted by too good to be true statements. Anyway - its about selling in order to buy - now thats not a bad idea, but I think it could be made a little clearer.
Sphere It
Leave Comment » | Posted in Thoughts
April 24th, 2007
Have you used and iframe and not like the 3D border around it? Here is what you do to not only style the border with CSS, but also to give the frame a background-color in IE.
<iframe id="myframe" src ="whatever.html" scrolling="yes" frameborder="0" allowtransparency="true"></iframe>
iframe#myframe{
border: 1px solid #D6EBF3;
background-color: #F5FAFC;
}
Sphere It
Leave Comment » | Posted in Web Development
April 24th, 2007
I am trying to collect a list of commonly used regular expressions in PHP, which I will add to when I come across them. They are useful for validation of forms and user input in general.
Regular Expression : Email Address Validation
$regexp_email =”^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$”;
Regular Expression : Name Validation
Allow for John Smith, John Smith-Jones, John O’Leary up to a max length of 50 characters
$regexp_name =”^[a-zA-Z-’\s]{1,50}$”;
Regular Expression : Remove multiple spaces in a string
$string = ” Red and yellow and pink and blue, orange and purple and green”;
$newstring = eregi_replace(” +”, ” “, $string);
echo($newstring);
Notes :
. matches any single character not including new lines
? matches zero or one of the previous character
* matches zero or more of the previous character
+ matches one or more of the previous character
Sphere It
Leave Comment » | Posted in Web Development
April 22nd, 2007
Here is an update to a previous post on finding longitude and latitude values for European towns and cities. The web site that did this recently changed their web site so my instructions for finding GLatLng values have been updated.
You can find the updated instructions here
Sphere It
Leave Comment » | Posted in Web Development
April 12th, 2007
Or put more simply, how to find Google Maps API GLatLng (longitude and latitude) parameters for anywhere in Europe easily. Google now provides a geocoder, but if you want an easy way to find co-ordinates manually - here it is.
Michelin has a superb route finding service as anyone who has used it to drive around in Europe will know, and their website covers most of Europe so there shouldn’t be many places we can’t find using it. I have used it for finding longitudes and latitudes in France, Spain, the UK and Italy for example.
Google Map has an API interface, and you can call GLatLng with the appropriate parameters to map any chosen location like this :
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
The example above gives the longitude and latitude for somewhere in California - as given in the example on the Google API help pages.
OK - so you want to find an accurate longitude and latitude for a little mountain village in France called Le Biot, France 74430. This is how I do it.
- Go to viamichelin
- Click on the maps link on the horizontal menu
- In the box on the left hand side, select the country of France
- Type 74430 Le Biot into the postcode, city,area field
- Click on search and you come up with a detailed map of the area, with Le Biot in the centre, marked with a symbol suggesting this is the exact point we were searching for.
- At this point there is also a white bubble that appears on the map containing more options
- In this bubble, click on the link that says send this address to GPS.
- When the send to GPS pop up appears, provide a file name (with no spaces) then click on Send.
- Open the file with notepad
- You will have a file (in this case) called le-biot.xvm
- The file contains a string with the precise longitude and latitude values, in this case : longitude=”6.63296″ latitude=”46.26209″
- Voila!
If you found this useful - please let me know by leaving a comment. Thanks.
Sphere It
3 Comments » | Posted in Web Development
April 8th, 2007
Or sometimes known as the div behind flash problem. I am working right now on a web site that is, how can I put it, quite demanding. It uses a multitude of technologies and 3rd party components including
- Flash - put together using 3DFA
- Monoslideshow
- A DHTML menu from Open Cube
- SWFObject to embed the Flash movie in the page elegantly
My DHTML drop down menu was unfortunately hidden behind my flash movie. A quick search on Google revealed this has been a common problem in the past, but not so much now.
OK - the DHTML menu from Open Cube sits at the top of the page, horizontally, with drop downs that drop quite far down the page. The Flash movie runs in the way of the drop down portion of the menu and was coming out behind the flash movie instead of in front of it.
Fix the div behind flash problem
To make sure this does not happen (at least in FF and IE’s more recent versions), and using the fabulous SWFObject - do this:
The parameters quality and wmode are the important ones to note.
<div id="slideshow1">
<img src="../slideshow1/noflash.jpg" width="266" height="170" border="0" />
</div>
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("../slideshow1/monoslideshow.swf", "ss1", "262", "170", "7", "#FFFFFF");
so.addVariable("dataFile", "../slideshow1/monoslideshow.xml");
so.addVariable("showLogo", "false");
so.addParam("quality", "high");
so.addParam("wmode", "transparent");
so.write("slideshow1");
// ]]>
</script>
Sphere It
Leave Comment » | Posted in Web Development
April 7th, 2007
Sometimes a fast image rollover can be quite effective. I needed to create an image rollover effect on a web site I am making at present. On the page are two small outline maps, one of France and one of Italy. The idea is that when the user hovers over the map, I simply switch images.
The link you need is like this :
<a class="italy" href="yourpage.html"></a>
The CSS is like this :
a.italy {
display: block;
width: 140px; /* width of image */
height: 185px; /* height of image */
background-image: url(../site-images/map-italy.gif); /* original image */
background-repeat: no-repeat;
}
a.italy:hover {
background-image: url(../site-images/map-italy-over.gif); /* target image */
}
Sphere It
Leave Comment » | Posted in Web Development
March 29th, 2007
It’s easy to get lazy. I wrote this to get my form to submit via javascript when the user clicks on a link, rather than on a standard submit button :
<a href="javascript:loginform.submit();">Click This</a>
It worked in IE, but failed to do anything at all in Firefox. You need to use the correct syntax for Firefox. Try this instead and the form submits in Firefox too.
<a href="javascript:document.forms.loginform.submit();">Click This</a>
Sphere It
Leave Comment » | Posted in Web Development