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.
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;}
My host recently started allowing remote connections to its mysql database. It was a really useful feature – I could not change database settings from my own computer. Since it started allowing remote connections from my IP, I could use any mysql client to connect to it. I fired up terminal and tried to connect using the command:
mysql --host=69.89.31.242 --user=username --password=password
It connected. This was just to test the connection. I wanted to connect my phpmyadmin with this remote host. For that I edited /etc/phpmyadmin/config-db.php file and changed:
$dbserver=”;
to
$dbserver=’69.89.31.242′;
I loaded the url http://localhost/phpmyadmin, entered the database username and password and I got in. I could administer my database from my local phpmyadmin installation.
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.
In a recent project, I had to output to a PDF file as well as to the browser. For this purpose first I downloaded the library from here. Then this code: