header
 
     
 
pixel
pixel pixel

Disabling code for local testing

I always program my PHP code locally (on my own computer) before uploading my pages to the live server. Most PHP code works fine locally but there are occasions where I don't want my PHP code to run locally. Eg - the PHP function mail() doesn't work on my local computer as I haven't installed a mail server. Most of the time I simply comment this code out with // at the start of the line (or using /* */ around chunks of code) but sometimes for pages that require a lot of testing and back-and-forth, all the chopping and changing can be a real pain. In these cases, I 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($Recipient, $Subject, $Body, $Headers);

Unhelpful Helpful
Comments
Comment by Cathleen on 2011-12-15
Ho ho, who wlouda thunk it, right?

Post a Comment
Name
Email
(optional)
Comment
RatingUnhelpful Helpful
Security Image* (this is just to prevent spam submissions)
Security Image