Disabling php code for local testing

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);

Leave a Reply

You must be logged in to post a comment.


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.