Monthly Archives: August 2011

Database config for localhost and server

To easily toggle database config for localhost and server, you can simply check whether you are accessing the local or server.

1
2
3
4
5
6
7
8
9
10
11
12
13
if (preg_match("/localhost/i", $_SERVER['SERVER_NAME'])) {
define ('DBHOST','localhost');
define ('DBNAME','localdbname'); 
define ('DBUSER','localuser');
define ('DBPASS','localpass');
define ('DEV',TRUE);
} else {
define ('DBHOST','localhost');
define ('DBNAME','serverdbname'); 
define ('DBUSER','serveruser');
define ('DBPASS','serverpass');
define ('DEV',FALSE);
}

Inserting recaptcha to your form

Captcha is good to reduce spam. One of most popular captcha used is recaptcha.

This is how it looks like. Familiar?

captcha

To implement it is very easy. Will take less than 10 minutes of your time.

1. Get your public and private key

https://www.google.com/recaptcha/admin/create

2. Include class file

Download recaptcha library file for PHP (with some sample files)

3. Insert code in form page

1
2
3
4
5
6
7
8
<form method="post" action="verify.php">
        <?php
          require_once('recaptchalib.php');
          $publickey = "your_public_key"; // you got this from the signup page
          echo recaptcha_get_html($publickey);
        ?>
        <input type="submit" />
</form>

4. Insert code to validate code in process page

1
2
3
4
5
6
7
8
9
10
11
12
13
14
require_once('recaptchalib.php');
  $privatekey = "your_private_key";
  $resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);
 
  if (!$resp->is_valid) {
    // What happens when the CAPTCHA was entered incorrectly
    die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
         "(reCAPTCHA said: " . $resp->error . ")");
  } else {
    // Your code here to handle a successful verification
  }

Resume do’s and don’ts

If you are sending out resume to apply for job, please follow the following rules

  • Prepare and send your resume in PDF format. With this your resume formatting will appear same all the time
  • Please always include your LATEST and most PRESENTABLE photo
  • Don’t name your file as resume.doc. Use resume_yourname.pdf instead. Remember not only you that send resume to apply for the job
  • Use email with your real name, not your cat’s name or whatever crazy name. For example abdul.rahman@gmail.com NOT setan_cute@gmail.com
  • Tell about your experience and what you HAVE DONE. Not about what subjects you took during your study. Describe the task, your role and other related information (e.g. technology used, party involved etc)
  • There is no limit of page for a resume. Don’t buy to idea that you need to limit to 1 page, 2 pages or maximum 4 pages. If you write the right thing, people will read it from beginning to the end

Update with join table

To update a table with a condition within other table (to join table), you can use this statement

1
2
3
UPDATE table1 a, table2 b
SET a.field6 = value
WHERE a.field1 = b.field1 AND b.field2 = value2

MySQL insert into select

This SQL statement to be used to insert data into a table from another different table.

1
2
3
INSERT INTO table1 (field1)
  SELECT table2.field2 FROM table2 
  WHERE table2.field2 > 100;

Be careful with ambiguous fields. So put the table name in front of the field name.
Also be careful with duplicate data inserted to the table.