Time of Day – greeting

Several people have asked me about the greeting on my website (www.jez-d.co.uk), which is different depending on the time of day. Basically, I have been asked how I did it. It was quite simple actually. I just wrote a script to detect the time of day and display different text, depending of what the time is. Anyway, here’s the script.

<?php
$daytime = gmstrftime(“%X”,time());
if (($daytime > “11:59:59″) && ($daytime < “17:00:00″ ))
$greet=”Good afternoon”;
else
if ($daytime > “16:59:59″)
$greet=”Good evening”;
else
$greet=”Good morning”;
echo $greet;
?>

Very simple, but does the job nicely.

Thwart the email harvesters and spammers

Ever wondered why you get so much spam email?

One of the reasons could be that you have a mailto link on your website. Harverster programs have been around for a while now. They surf the Internet looking for such email links in order that they can send these unsolicited email ads – or even those wonderful emails telling you that a relative of a deposed African dictator has €1000 million secreted away and your help is needed etc.

Ok. I’ll now show you three ways which will reduce the likelyhood of this happening.

Several years ago, I read that these harvester programs ignore all code enclosed in <script> tags. So I came up with this little gem:

<script type=”text/javascript”>document.write(‘<a href=”mailto:’)</script>
me@mine.co.uk”>Email</a> link there

Basically, you replace your <a href=”mailto…… with this little script. The idea is that the harvesters cannot read the mailto portion of the script and therefore does not harvest the email address.

However, not long after, I read that new harvesters can now read code enclosed in <script>, but do not read anything included in the <head>. So I came up with this very simple alternative:

function message(){
location.href=’mailto:me@emailaddress.co.uk’;
}

This can be in either the <head> or a separate .js file. Call it with something like:

<a href=”javascript:” onclick=”message()”>Email link</a>

Not as messy as the first example!

Latest information I have read, is that the Harvesters can read this too. So I did a little bit of reasearch and found that replacing any of the letters in your email address with hexidecimal equivalents may do the job. Most harvesters look for the @ character in the email address, so I replace that with its hex equivalent:

&#x40

followed immediately by a ;

At the moment only a very small minority of harvesters can read this, but I wonder how long that will be the case!!

Submit a form and reload the page without the form

Had an issue recently with a university project where my team wanted to have a contact form on a webpage, to capture the usual contact info from website visitors. However, this would take us to the maximum number of pages allowed, and so, we could not have a “thanks, message sent” page.

Here’s how I did it:

  1. When the page containing the form loads, it checks if $_SESSION is set for form. If not, it
    displays the form within the page, otherwise displays a custom message in the page – but
    no form.
  2. When the form is submitted, the script sets $_SESSION for the form and then reloads the
    page. This has the added advantage that the form cannot easily be submitted umteen times.

Ok.Your form needs to contain something like this:


<?php

session_start(); //Set Session Data.

if (isset($_SESSION['form_name'])){ //this line checks if session id is set

//if session ID is set, form has already been sent so display custom message

echo ‘<br />Your email has been sent, thanks.<br /><br />’;
} else {//session ID not set so display form

//Put form HTML in here

}
?>

The form sends the data to a script called send_form.php, which looks like this:

<?php

//Set Session Data
session_start();//this line sends a cookie called PHPSESSID

//insert here script to validate & send data

$_SESSION['form_name'] = TRUE; // set session ID for the form

//Next, relaod the same page
print “<meta http-equiv=\”refresh\” content=\”0;URL=page.php\”>”;

?>

I tested it on the wireframe and it worked fine.

Welcome

Ok. Where to start.

This is my first attempt at weblogging, so it will be a learning experience for me. It seems to be the way forward these days. Actually, one of the directors of a Manchester-based firm recommended I start one. Having given it some serious thought, I have decided to give it a try.

So what will be featured? Let me tell you that.

Those who know me will know that I am currently studying BSc(Hons) Web Development at manchester Metropolitan University. I am also using my own time to improve my own capabilities in web development. That includes PHP, XHTML, MySQL, SEO (search engine optimisation) and asp.net. This blog will be dedicated to featuring what I learn as well as any particular scripts I create to serve prescribed purposes.