PHP Tips & Tutorials

How to execute / run PHP scripts in the background?

If the website is run on a Linux server, everything that can be run from the web (i.e., from the browser address bar) can be run from the Linux console. That is if you have the SSH access which most hosts provide. Connect to your hosting server via SSH by putty and you will have the ultimate control over your box. For example, you can execute a PHP script called routine.php via SSH by:

/usr/bin/php5 routine.php #routine.php is in the current working directory

Depending on your distro and PHP installation options, the command line interpreter (in this case, /usr/bin/php5) may vary in location.

You can add this line to a crontab job and it the PHP script routine.php will be executed by your designated intervals or at any certain time, automatically.

Other than calling PHP scripts from Linux console via SSH, you can also call to execute PHP code in another script file from the current PHP file. For instance, in A.php:

exec('/usr/bin/php5 B.php');

As it obviously suggests, this line will run the Linux command ‘/usr/bin/php5 B.php’ and you can put stuff in B.php that will be taken care of when this line in A.php is executed.

There are a variety of different PHP functions that perform essentially the same task, running system commands: exec, shell_exec, system and passthru.

PHP Tips & Tutorials

PHP: Delay Function that Halt Code Execution Temporarily and Then Resume It

Sometimes you need to temporarily halt the code execution of your PHP script for certain seconds and then automatically resume it. For example, some mail delivery servers have the restriction that you have to wait a certain interval such as 12 seconds before sending another email.

You can tell your PHP script to stop for 12 seconds before continuing down with the rest of the code by sleep() function:

sleep(12); // freeze PHP execution for 12 seconds before going ahead

That’s it. When it is executed to this line, PHP will freeze for 12 seconds, doing nothing, and then go on with the line immediately after this line.

PayPal & Ecommerce

Way to go PayPal! – Fraudulent Chargeback Successfully Resolved in Merchant’s Favor

I made a sale months ago when someone purchased a few website scripts for over $1,500. A few days after the transaction he fired a chargeback dispute. I thought, well ok, I’m puked. I almost gave in. But then I thought I couldn’t let him win this easily.

So I provided everything I can with regards to the dispute case in the PayPal resolution center, including transaction logs, email communications and several screenshots of proof that he had received the digital goods. A few days later, the funds are transferred away anyway. I lost.

This morning, however, PayPal sent me an email, over 100 days later:

Hello Kavoir,

We are pleased to inform you that we have successfully disputed chargeback
case #PP-xxx-xxx-xxx-xxx.  The buyer’s card issuer has decided in your
favor and within seven days you will receive reimbursement for $xxxx.xx USD.

This is truly a surprise and a good one. You can imagine the look I had when I read the message. To make sure, I logged into my PayPal account and saw the funds right reimbursed.

How awesome is that.

JavaScript Tips & Tutorials PHP Tips & Tutorials

PHP and JavaScript Variable / Value Transfer / Exchange: How to pass variable values from PHP to JavaScript or JavaScript to PHP?

This is a rather common problem for novice web developers. While it may seem at first glance that it’s easy for PHP and JavaScript to communicate with each other, but they actually cannot interact with each other directly. They are very different technologies built for distinct purposes.

How to transfer or pass variable values from PHP to JavaScript?

To pass variables or values from PHP to JavaScript, just write the PHP code to generate the client side JavaScript code as you would with HTML code:

var jsVar = "<?php echo $phpVar ?>";

To embed PHP code in *.js files you have to first make the server to parse JavaScript .js files for any PHP code so that they will be executed. After that, you can create classes or call to functions or do whatever that is allowed in PHP in the .js files just as you can with .php files.

How to transfer or pass variable values from JavaScript to PHP?

Simply put, you have no other way to let some PHP script know any variable value than to send a request to it. So, you will use JavaScript to send a request to the PHP script by a GET or POST request that bears the variable value.

You can trigger a redirection to the PHP script and pass the values via URL:

var age = 24;
document.location = '' + age;

Or you can perform an XMLHttpRequest request by GET or by POST.

JavaScript Tips & Tutorials PHP Tips & Tutorials

How to execute / run PHP code inside JavaScript files?

Static files of JavaScript would survive most applications but sometimes the ability to include PHP code inside JavaScript scripts and generate the content of the script files on the fly by PHP is a better option. How does one do that?

The simplest solution is to just include PHP code inside the <script></script> section of your HTML templates / web pages because chances are, the file extension is .php:

var jsVar = "<?php echo $phpVar ?>";

Even if it’s not ending in .php, such as in .html or .htm, you can configure your server to parse all .html or .htm files for any PHP code, though with a little extra server burden.

Another solution for this is to make your server parse all files ending in .js. Just create a .htaccess if it doesn’t exist in the directory in which you wish to include and run PHP code inside all .js files. Add these lines at the end of .htaccess:

AddType application/x-httpd-php .js
AddHandler x-httpd-php5 .js

<FilesMatch "\.(js|php)$">
SetHandler application/x-httpd-php

Now you can add all the PHP code you can inside any JavaScript files with a .js extension, the server will automatically parse and run them when the client side requests the file.

SQL / MySQL Tips and Tutorials

MySQL logic operators: How to use AND, OR together in WHERE clauses in one query?

AND and OR are common logic operators across all programming languages and in MySQL, they mean the same thing. A statement (a.k.a, a condition in any WHERE clauses such as id > 100) can be either true or false. A group / combination of statements can be true or false, depending on their own values (true or false) and the logic operators that have joined them.

AND and OR each can join 2 statements.

AND – both statements must be true

For example, in this MySQL query:

SELECT * FROM student WHERE age > 10 AND grade < 4

All students who are graded less than 4 and older than 10 will be selected. The logic operator AND commands that both of the conditional statements (age > 10 and grade < 4) must be true for the whole statement (age > 10 AND grade < 4) to be true. You can add more conditions and ask them all to be true to narrow down the selection:

SELECT * FROM student WHERE age > 10 AND grade < 4 AND sex = 'female'

Which effectively selects all the female students who are older than 10 and have a grade of lower than 4 because the AND operators mean that all 3 statements must be true for the whole, joined statement (age > 10 AND grade < 4 AND sex = ‘female’) to be true.

OR – at least one statement must be true

Consider this example,

SELECT * FROM student WHERE grade > 4 OR grade < 2

This simply selects all the students who have a grade higher than 4 or lower than 2. All the students who satisfy one or more of these statements are selected. Students who satisfy none of these statements are neglected. You can as well use more than one OR in a series:

SELECT * FROM student WHERE grade > 4 OR age < 9 OR surname = 'Bush'

So that any student who has a grade higher than 4 or is less than 9 years old or has a surname of Bush will be selected.

How to use AND and OR together?

Consider the following example,

SELECT * FROM student WHERE grade > 2 AND grade < 5 OR age > 8 AND age < 12

As AND has a higher priority (effectively so in almost all programming languages) than OR, it will be evaluated before any OR statements. Therefore, this query will select all those students whose grade is higher than 2 and lower than 5 or those whose age is older than 8 and younger than 12.

You can add parenthesis but because AND has a higher priority in parsing the logic statement, it’s the same:

SELECT * FROM student WHERE (grade > 2 AND grade < 5) OR (age > 8 AND age < 12)

However, as parenthesis has the highest priority, if you add them in a different way such as this:

SELECT * FROM student WHERE (grade > 2 AND grade < 5 OR age > 8) AND age < 12

It would give completely different results. Firstly, grade > 2 AND grade < 5 must be true or age > 8 must be true, secondly, age < 12 must be true. For example, these students will satisfy this WHERE clause:

  1. grade = 4, age = 7
  2. age = 9
  3. grade = 3, age = 11

These students don’t satisfy this WHERE clause:

  1. age = 14
  2. grade = 5, age = 7
PayPal & Ecommerce

This payment cannot be completed and your account has not been charged. Please contact your merchant for more information.

Very rarely you may encounter this error after you have clicked the “Pay Now” button on PayPal to send payment to someone / merchant in purchase of something:

This payment cannot be completed and your account has not been charged.  Please contact your merchant for more information.

paypal error: This payment cannot be completed and your account has not been charged.  Please contact your merchant for more information.

At first, I blamed my website payment integration on Convert Hub and thought that something about my merchant account (business account) at PayPal might have gone wrong.

However, I later found out that it’s actually because of my personal account which I used to pay to my merchant account. My personal account of PayPal was somehow limited at that time and could not send money by any means.

After providing necessary documents to verify my legal ownership of the account, its full access was restored and I tried a test payment via the “Buy Now” button at here. There was never any errors any more and the payment was successful.

My Personal Reviews, the Design Contests Platform – From Outsource to Crowdsource

When you need something done, design contests are a much better way to get the quality and diversity you need than traditional design outsourcing because you get multiple submissions from various designers who are after the bounty prize. It may be a little more expensive than when you hire just one designer, but the quality and diversity you get will definitely justify it. Not to mention the time you will save for communications with the one designer as well as later revisions. is just such a contest platform that enables you to get what you need without spending an arm and a leg. You can get all the talents working for you on a single project by launching a contest. Be it print, web, audio or video, you can get all the input in just a few days and then decide which one you’d like to accept as the winner so that the designer can claim the prize you are paying. It’s perfect for a logo or advertisement banner design.

Client Side Coding Books CSS & HTML Tips Rich Internet Application

Best and Newest HTML5 Books (and Some CSS3 Books)

HTML5 and CSS3 are becoming a reality. To be better prepared and armed with the latest technologies of the web so that we stay on the cutting edge when creating stuff, I have found some of the best book titles at Amazon about HTML 5 and CSS 3. Note that several of these books have not been released yet. You can pre-order and receive them when they are out.

Web Developers / Designers’ Books:

  1. Best HTML Books
  2. Best CSS Books
  3. Best JavaScript Books
  4. Best PHP Books
  5. Best MySQL Books
  6. Best Linux Books
  7. Best Apache Books (mod_rewrite Books)
  8. Best Web Hosting Books

HTML5: Up and Running

html 5 up and running

Here’s a godsend online book for learning HTML5 written by Mark Pilgrim as well.

HTML5: Designing Rich Internet Applications (Visualizing the Web)

HTML5 Designing Rich Internet Applications (Visualizing the Web)

Beginning HTML5 and CSS3: Next Generation Web Standards

Beginning HTML5 and CSS3 Next Generation Web Standards

Pro HTML5 Programming: Powerful APIs for Richer Internet Application Development

Pro HTML5 Programming Powerful APIs for Richer Internet Application Development

Introducing HTML5 (Voices That Matter)

Introducing HTML5 (Voices That Matter)

Beginning iPhone Web Apps: HTML5, CSS3, and JavaScript for WebKit

Beginning iPhone Web Apps HTML5, CSS3, and JavaScript for WebKit

HTML5 Now: A Step-by-Step Video Tutorial for Getting Started Today (Voices That Matter)

HTML5 Now A Step-by-Step Video Tutorial for Getting Started Today (Voices That Matter)

HTML5 Straight to the Point: Using HTML5 with CSS3 and JavaScript

HTML5 Straight to the Point Using HTML5 with CSS3 and JavaScript

CSS3: Visual QuickStart Guide (5th Edition)

CSS3 Visual QuickStart Guide (5th Edition)

Internet Tools Web Applications & Online Software

How to delete a Skype account so that it doesn’t appear in search?

Several of the Google results for ‘how to delete Skype account’ suggest that you can’t literally delete any Skype account once created. However it really bothers me that more than one account under one email address would definitely confuse people who have searched for you and are trying to figure out which one is the regular account of yours. Half of the chance is that he or she would end up with the wrong one.

So how can you delete extra Skype accounts so that you have only one user account under your email address?

The answer is you can’t. But you can change the registered email address of the extra accounts. Just sign in to your Skype account and go to to perform the change. After the change, people will see no more unwanted accounts under the original email. Problem solved.