Disabling php code for local testing
Generally we used to program our PHP code locally (on my own computer) before uploading to the live server. Most PHP code works fine locally but there are few PHP code is not run in locally. Eg - the PHP function mail() doesn’t work on local computer, if we haven’t installed a mail server.
In these cases we used to comment this code out with // at the start of the line (or using /* */ around chunks of code). But instead of comment out these functions we can use an If statement to check if the website is local or live and execute the code based on the result:
if ($_SERVER[’SERVER_NAME’] != “localhost”)
mail($tomail, $subject, $body, $headers);
