Blogs

Running Server Commands in PHP

Here I will discussed how to run commands on the server. There are many PHP functions available for executing server commands.

For starters, there is exec():

exec(command, $output);

This function takes a command and assigns to $output an array where each
element is a line of the generated output.

There is also system(), which just returns the output (so that it could be immediately sent to the Web browser):

system(command);

The passthru() function is similar, but it can also return binary output:

passthru(command);

Finally, you could use shell_exec() or the backticks, both of which just return the output:

$var = shell_exec(command);
$var = 'command';

For security purposes, you should use escapeshellarg() or escapeshellcmd()
to sanctify any command that isn't hard-coded.

Using Mail_Mime

PHP's built-in mail() function is simple to use, but it does have its shortcomings. For starters, you cannot use it with an SMTP server that requires authentication. Second, it’s not very easy to use it for sending HMTL email or email with attachments. A solution is to use PEAR’s Mail and Mail_Mime classes.

In layman’s terms, Mail_Mime turns the information you need to send—be it HTML or attachments—into the proper syntax for an email message. The Mail class is then used to send that message.

Sending HTML email

To start, you’ll need to include two class definitions (after having installed both PEAR packages, of course):

require_once (‘Mail.php’);
require_once (‘Mail/mime.php’);

You’ll also want to establish your message body. For HTML emails, you should create a plain text and an HTML equivalent. For the HTML content, it should be a complete HTML document:

$text = 'Plain text version';
$html = 'Your HTML part';

Now create a new Mail_Mime object:

Performing IP Geolocation PHP

Although the server where PHP is located could be anywhere in the world and the user could be located anywhere in the world, it is possible to make a geographic match. The premise is this:

Search Engine Optimizations Tips

The word SEO is an acronym for Search Engine Optimization. It is a term used to describe how to design web pages for the highest possible placement in search engine results pages.

Organic SEO relates to the website code and pages within the site. It has nothing to do with link development or any other type of external Internet marketing. There are literally dozens of SEO do's and don'ts you should be aware of when designing your website. Understanding the answer to the question what is SEO? is fundamental to effectiveness of your ranking in the search results.

Here are some of my SEO tips:

It would be a waste of your time to optimize your website for keywords that are not even being searched for. Therefore you should invest some energy into finding the best keywords. There are several SEO tools available on the Internet to help you find the best keywords.

Using PECL Filter

New in PHP 5 and quite promising is the Filter library of PECL code. Being developed by PHP’s creator and other major contributors, the future of Filter looks bright, even though it’s still in beta form (at the time of this writing). The Filter package provides two types of security:
◆ Data validation by type
◆ Data sanitization
What Filter offers is a unified interface for performing common types of validation and sanitization. For example, I might commonly use code like this:

if (isset($_GET[‘id’])) {
if (is_numeric($_GET[‘id’])) {
$id = (int) $_GET[‘id’];
if ($id > 0) {
// Do whatever.
}
}
}

I could instead do this:

$id = filter_input(INPUT_GET, ‘id’, FILTER_VALIDATE_INT, array(‘options’=>array(‘min_range’=>1)));
if ($id) { …
//Dow whatever.
}

Cumulus Tag Cloud

Kiran Says

I love work environment which is:

Informal yet professional
Demanding yet rewarding
Challenging yet inspiring
Mediocrity is not an option
Having fun is serious business
Making mistakes is human
Forgiveness is Company Policy

Travelling Sucks