We can check the php configuration, apache’s loaded modules and all other kinds of PHP configuration using a simple function called phpinfo(). Create a file called infophp.php in your web’s root directory and put the following code in it:
<?phpinfo();?>
This would output all the php configuration info and apache information. You can pass on an argument to phpinfo() to limit what information is displayed. You can checkout the phpinfo documentation here.
PS: This is a beginner tutorial for absolute beginners.
There’ve been lots of times when I wanted to use the mail() function on my local server. I am sure lots of you would’ve been wanting it too but most of you would’ve settled for PHPMailer or just used a web host to test the code instead. I myself had been doing the same until recently when I finally decided to do some research and get it to work.
Here are the steps in short for the geeks who like to do things on their own: All I did was used smtp client called msmtp, configured it to work with my gmail account and configured PHP to use msmtp to send emails.
This tutorial is only applicable for linux users. I’ll write another article for windows users soon when I get my hands on a windows box. All the commands used in the instructions are for Ubuntu, however you may use corresponding commands for your distro (for eg; you can use yum install instead of apt-get install on fedora, redhat, centos.
Here’s a function which thoroughly checks email-address and returns true for a valid email address and returns false for invalid one. I thought it was worth sharing so I posted it on my blog. You will find the source link at the bottom.
/**
Validate an email address.
Provide email address (raw input)
Returns true if the email address has the email
address format and the domain exists.
*/function validEmail($email){$isValid=true;$atIndex=strrpos($email,"@");if(is_bool($atIndex)&&!$atIndex){$isValid=false;}else{$domain=substr($email,$atIndex+1);$local=substr($email,0,$atIndex);$localLen=strlen($local);$domainLen=strlen($domain);if($localLen<1||$localLen>64){// local part length exceeded$isValid=false;}elseif($domainLen<1||$domainLen>255){// domain part length exceeded$isValid=false;}elseif($local[0]=='.'||$local[$localLen-1]=='.'){// local part starts or ends with '.'$isValid=false;}elseif(preg_match('/\\.\\./',$local)){// local part has two consecutive dots$isValid=false;}elseif(!preg_match('/^[A-Za-z0-9\\-\\.]+$/',$domain)){// character not valid in domain part$isValid=false;}elseif(preg_match('/\\.\\./',$domain)){// domain part has two consecutive dots$isValid=false;}elseif(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',str_replace("\\\\","",$local))){// character not valid in local part unless // local part is quotedif(!preg_match('/^"(\\\\"|[^"])+"$/',str_replace("\\\\","",$local))){$isValid=false;}}if($isValid&&!(checkdnsrr($domain,"MX")||checkdnsrr($domain,"A"))){// domain not found in DNS$isValid=false;}}return$isValid;}
One of my clients got this error in his wordpress:
Error establishing a database connection
It is one of those vague errors which give very little information about what caused it. On going to /wp-admin, it gave error:
One or more database tables are unavailable. The database may need to be repaired.
I added “define(‘WP_ALLOW_REPAIR’, true);” in wp-config.php and clicked on ‘repair’, it showed that all tables have been repaired but I was still getting the error about wordpress not being able to connect with database. It was actually able to connect but there was some other problem. I checked if any table was missing from the database, but it was not.
Finally after 2 hours of searching for a solution, I found it. In wp-options table, just make sure the option_value for the option_name ‘siteurl’ is your site’s url. You can also do this by executing the following sql statement (you can use phpmyadmin): Read the rest of this entry »
We all know about functions and how we can pass arguments to it. But did you know that we can pass variable number of arguments in a function?
Consider a function sum() which adds numbers passed into its arguments. Now we want it to add all the numbers passed onto the arguments. Eg; if we call sum (21, 45) or sum (45, 23, 78, 56, 90) it should add all of them. Even if we pass a 100 arguments, it should execute successfully.
Flushing the output buffer doesn’t works in PHP sometimes no matter what you do. I had this code which would never work on my server but would perfectly fine on localhost. This was the code.
Well, you might have seen a huge number of variable checks ranging from is_file(), is_array() to is_numeric() and is_int(). While developing a script today I wanted to check for alphabets. I directly used is_alpha() but to my surprise it wasn’t defined.
I’ve developed my own libraries for rapid development of PHP applications. Email library is one area which I didn’t feel like developing a library for. Just then, I remembered how simple and robust CodeIgniter’s Email class was. I decided to try it on my own script. It was not at all difficult to get it working. It just commented out few lines of codes and voila! I was able to send my first email.
Those who are in need of a email library could use this simple library separately. I’ll guide you through the whole process step by step.
First thing you need to do is copy the Email.php from system/libraries folder and place it inside your script. Then use your favorite IDE to edit these lines: Read the rest of this entry »
So, you thought you would make a web application but didn’t know where to start? This is the place to start. You need a web server installed on your computer before you start any kind of web programming be it PHP, ASP .Net, ColdFusion, JSP.
For developing in PHP, you would have to install an Apache HTTP server, php interpreter, MySQL server. Installing all of them would be a real headache and so would be configuring them to work with each other. To simply this we have WAMPs(Windows Apache, MySQL, PHP).
One such WAMP distribution is XAMPP which is cross platform and has many features inbuilt like filezilla ftp server, a mercury mailing server etc.