Simple Plugin For Wordpress to Show Adsense

August 28th, 2008

Now my blog has one hundred posts. I think my knowledge is worth some money that’s why I decided to add some Ads. All I know is shared absolutely for free and I don’t like any donations. I think Adsense is good enough to monetize my blog. My earnings will be announced; I don’t know what will be the revenue.

I’ve been searching for a good yet simple Wordpress plugin, that could allow to add ads to my blog. I’ve tried several, but none of them seemed to be good for my needs. After some experiments I’ve chosen
All in One Adsense and YPN. It was exactly what I needed.

This plugin has only one file, that’s good enough as it is simple to delete it if you decide you don’t need it. The second advantage is the easy setup. Basically, all you need is your adsense publisher ID; all other settings may be left as they are; you need just to select the number of ad blocks and you’re ready to go.  Here is how it looks in my browser:

Everything is clear and easy to set up. I didn’t think adding ads is such an easy task! By the way, plugins I’ve tried were found here:

How To Protect a Folder Using .htaccess From Command Line

August 28th, 2008

We do often meet password protected directories on the Web. This is usually used to hide some information that should not be visible to all site users. Most common is .htaccess protection, that allows you to restrict users at Apache level and is also knows as http authentification. Today I will tell you how to protect your directory using command line.

As usually we need root access to the server and need to go to the folder which is waiting to be protected. First of all we need to create an .htaccess file that should contain the information that authentification is required to access this folder. The most common sample comes below:

AuthGroupFile /dev/null
AuthName “Closed User Group”
AuthType Basic
AuthUserFile /path_to_htpasswd_file/.htpasswd
require valid-use
r

Usually .htaccess and .htpasswd files are located in the same folder, but you can move .htpasswd anywhere you like: you will just need to point to its absolute location in .htaccess.  Then go to the directory where you’re planning to put your .htpasswd file.

Now we need to have username and password - that’s enough. The following command will create your .htpasswd file with login data so you can use it immediately.

htpasswd -bcm .htpasswd user password

You can read more about this command at Apache Site. But this command will help you to create a password file without any specific knowledge.

Please, note that .htpasswd is just the file name: you’re welcome to store your passwords in the files with any file names, but it would be better if it is started with a dot and if this file is stored in the directory that is not accessible from web.

How to Install Zip Functions Support For PHP

August 25th, 2008

Using zip files is a common practice for web. Zip archives are very useful as they are supported by all major operating systems and don’t require any special software. XP and Vista have the embedded support of this file format, you won’t also have problems opening these files in Linux. You can also work with these files in PHP. in order to do this, you should have ZZIPlib installed - it allows the easiest way to work with zip archives.

In this article I will tell you how to add zip file support for your PHP installation. As usually, we will need root access to our server with PHP compiled from source files.

In this article I will describe how to add zip support to PHP5 as it is installed at most servers at the moment. My OS is CentOS, but the installation should not differ from other operating systems, it’s easy enough to add zip functions.

First of all we need to ensure we have zlib installed. Run rpm -qa | grep zlib to check whether it is already installed and install it using yum if it is not present in the list created by the output of previous command. yum install zlib* should install everything related to zlib - that’s what we need to run zip.

Then run phpinfo() and copy the configure line you have. It should look like: ./configure –with-apxs –with-curl –with-curl-dir=/usr/local/lib –with-gd –with-gd-dir=/usr/local –with-gettext –with-jpeg-dir=/usr/local/lib –with-kerberos, etc. Then you need to add –enable-zip to this line.

Then you need to go to the directory where PHP source files are located. If you server has Directadmin installed, you should go to /usr/local/directadmin/customapache - your PHP files should be located there. Then change directory to the one with PHP source files and run the configuree command with –enable-zip added. Then - make and make install as usually.

After this all you need is to reboot apache. Your PHP installation should now support zip functions.

Apache Stopped Working After PHP Upgrade - How to Fix

August 24th, 2008

If you are often working with PHP upgrades, you should do this automatically - you already know all the issues you might face. But if it’s done for the first time, it is quite hard to find your problem. I will tell you about the most common issue and about the applicable actions to fix this.

When you update your PHP installation via Directadmin build system or when you do this manually, new modules are added to httpd.cond, but the older ones are not deleted. This usually causes problems, as apache refuses to start after PHP upgrade, What do you need to do in order to tun apache again?

You need to edit your httpd.conf file (it is usually located at /etc/httpd/conf/httpd.conf). Open this file fith any editor you like and comment all strings that contain “php4″. The same directives for PHP5 are added automatically so you don’t have to worry about it. When you comment everything related to PHP4, you should save httpd.conf and try to reboot apache. If everything is OK, it should start, if not - you have to follow its logs or errors you receive at the command line window. Let me remind you that most useful way to restart apache is service httpd restart.

My Choice For System Backup for Windows - Acronis True Image

August 20th, 2008

Today I’ll tell you about an excellent software that allows to create any kind of info backups. That’s greatly important as you will be able to restore anything you like in just minutes. For example, if you have installed a fresh copy of Microsoft Windows, you know how much time it takes among with software setup. Acronis True Image Home will revert your system to the tuned condition in just minutes. I’ve got a Russian version that’s why I won’t post any screenshots here.

Acronis true image Home is a powerful software that allows you to deal with any kind of data backup. It comes with scheduler so you won’t even need to create your backups manually - you will just have to keep your backups in a safe place. The rest is done with this software - I consider it’s more useful than Norton Ghost (I’ve used it for some time).

Acronis True Image Home also comes with secure file shredder - you can now safely delete your files. You can also Protect your privacy by cleaning up your activity track stored by Windows.

I suggest you to download and install this software. I think you will be impressed with all the features it has and I think it’s worth its money

How to Modify Default Virtualhost Template in Directadmin

August 20th, 2008

If you own a Direactadmin server, most probably you would like to add something to default virtualhost settings, when a new user is created. You might need any specific php settings, or anything related to Apache - this doesn’t really matter. Let’s see where we can modify these settings; you will need SSH access to your server as we will edit a configuration file.

We need to go to the directory, where configuration templates are located. It is /usr/local/directadmin/data/templates. There are lots of files, but we need virtual_host.conf to make the necessary changes to default virtualhost settings.

A default file should look like this (this is the original version):

|?DOCROOT=`HOME`/domains/`DOMAIN`/public_html|
|?OPEN_BASEDIR_PATH=`HOME`/:/tmp:/usr/local/lib/php/|
<VirtualHost |IP|:80>
|CUSTOM|
|?CGI=ScriptAlias /cgi-bin/ `DOCROOT`/cgi-bin/|
ServerName www.|DOMAIN|
ServerAlias www.|DOMAIN| |DOMAIN| |SERVER_ALIASES|
ServerAdmin |ADMIN|
DocumentRoot |DOCROOT|
|CGI|

|USECANONICALNAME|

User |USER|
Group |GROUP|
CustomLog /var/log/httpd/domains/|DOMAIN|.bytes bytes
CustomLog /var/log/httpd/domains/|DOMAIN|.log combined
ErrorLog /var/log/httpd/domains/|DOMAIN|.error.log

<Directory |DOCROOT|>
Options +Includes -Indexes
|*if CLI=”1″|
php_admin_flag engine |PHP|
<IfModule !mod_php6.c>
php_admin_flag safe_mode |SAFE_MODE|
</IfModule>
php_admin_value sendmail_path ‘/usr/sbin/sendmail -t -i -f |USER|@|DOMAIN|’
|*endif|
|*if OPEN_BASEDIR=”ON”|
php_admin_value open_basedir |OPEN_BASEDIR_PATH|
|*endif|
|*if SUPHP=”1″|
suPHP_Engine |PHP|
suPHP_UserGroup |USER| |GROUP|
|*endif|
</Directory>
|HANDLERS|
|MIMETYPES|

</VirtualHost>

For example, we need to have a common include directory for PHP scripts, operated by many users. Certainly it is possible to go to /usr/local/directadmin/data/users and change include settings one by one. You can also edit php.ini, but this is the most unsecure solution.

In order to add a directory for common inclusion, we need to add it to the following string:

|?OPEN_BASEDIR_PATH=`HOME`/:/tmp:/usr/local/lib/php/:/YOUR_DIRECTORY|

This file is easy to understand so if you need to have some specific settings, it is quite easy to apply them. For example, if you need to use wildcard subdomains, you will need the following string:

ServerAlias *.|DOMAIN| |DOMAIN| |SERVER_ALIASES|

Any changes related to default Directadmin virtualhost should be made in this file.

If you need to apply changes to existing users, the glue is to run the following command via SSH:

echo “action=rewrite&value=httpd” >> /usr/local/directadmin/data/task.queue /usr/local/directadmin/dataskq d

This will apply the canges made to all users. All virtualhosts will be rewritten, so triple check the configuration before applying this command - in case of any error your sites may stop working.

Wordpress Stats - a Good Instrument for Blog Statistics

August 19th, 2008

Just went back from my trip to Turkey. I like that my blog visitors come day by day to read my posts even if I don’t write anything day by day. Today I’ll tell you about an official Wordpress plugin named Wordpress Stats.

Wordpress stats is a good solution for newbies who want to track where visitors come from. I consider it’s more informative than Webalizer is, as Webalizer’s data is hard to understand and you have lots of information you cannot use. Let’s take a look at Webalizer stats page to understand why it is recommended to install it.

This is the first screen that appears when you click the stats link. It shows you the number of your blog visitors day by day. Quite simple and useful.

The second page shows you how do people come to your blog and what pages are most popular.

The next one shows search engine terms, that is especially informative. You can track what keywords are relevant for your blog and what people are actually searching for to get to your blog.

Installation is very easy - you don’t need to do anything but upload a single file and get your Wordpress API code. Account at wordpress.com is created in one minute, so the stats system will be installed in some minutes. If you’re looking for a simple yet informative stats system for your Wordpress blogs - Wordpress stats is the solution.

Function to Extract The Value From a String With PHP

August 8th, 2008

If you’re working with text information, you often need to extract some parts of text from articles, web pages and so on. You can use regular expressions for this, but if you’re not familiar with them, you’ve got to use string functions of PHP.

When I didn’t know what regular expressions are, I’ve written a function that extracts the text you need from a string. It is useful when you need to parse forms, web pages for some exact information, etc. Here it is:

<?

function extract_value($source, $start, $end)
{
$pos=@strpos($source, $start)+strlen(stripslashes($start));
$pos2=@strpos($source, $end, $pos);
$len=$pos2-$pos;
$output=substr($source, $pos, $len);
return $output;
}

?>

Function above takes three arguments: text source, the first matching part and the second matching part. Function extracts the text between these two values. Sample usage is: $match=extract_value($result, “from here”, to here”); This is much easier than to deal with regular expressions, especially if you are new to PHP. This function is not for professionals, however it is a great solution if you often need to parse something from text without regular expressions.

How to Change Owner for All Files in a Folder Linux

August 6th, 2008

A system administrator often needs to deal with file ownership change. This is often related to the ownership of the files created by daemons. Often users don’t have access to the file created by apache. What to do if you need to change ownership of a group of files?

You must be root to perform this operation. The following command will change permissions to all files in the specified folder. This is related to user and group permissions so you don’t need to run chgrp command.

chown -R <user>:<usergroup> <folder>

This will recursively change ownership to the files located in the folder. Note that most web hosting panels create user groups with the same name as users’ so the command will most probably look like chown -R <user>:<user> <folder>. You can use any masks, for example, if you need to change ownership of html files only you need to issue chown -R <user>:<user> <folder>/*.html

This is quite a simple operation, however many people who want to take a look at their servers don’t know this. I hope this article will help you to manage your files

How to Create All Possible Word Combinations from a String With PHP

August 4th, 2008

Sometimes you need to change the word order in a line for some reason. I am going to show you a PHP solution that allows you to create all possible word combinations from a string. The code below should explain you all operations that are performed.

<?

// Factorial
function fact($s){
if ($s==0) return 1;
else return $fact = $s * fact($s-1);
}

$phrase=”Your Phrase Comes Here”;
// Let’s count the number of words by creating an array
$words=explode(” “, $phrase);
$n=count($words);

// Here comes a loop that creates all possible combinations of array positions
for ($m=1; $m<=fact($n); $m++)
{
$ken = $m-1;
$f = 1;
$a = array();
for($iaz=1; $iaz<=$n; $iaz++)
{
$a[$iaz] = $iaz;
$f = $f*$iaz;
}
for($iaz=1; $iaz<=$n-1; $iaz++)
{
$f = $f/($n+1-$iaz);
$selnum = $iaz+$ken/$f;
$temp = $a[$selnum];
for($jin=$selnum; $jin>=$iaz+1; $jin–)
{
$a[$jin] = $a[$jin-1];
}
$a[$iaz] = $temp;
$ken = $ken%$f;
}
$t=1;

// Let’s start creating a word combination: we have all the necessary positions
$newphrase=”";

// Here is the while loop that creates the word combination
while ($t<=$n)
{
$newphrase.=$words[$a[$t]-1].” “;
$t++;
}
// Output of the phrase
echo $newphrase.”\r\n”;

}

?>

The example above will output:

Your Phrase Comes Here
Your Phrase Here Comes
Your Comes Phrase Here
Your Comes Here Phrase
Your Here Phrase Comes
Your Here Comes Phrase
Phrase Your Comes Here
Phrase Your Here Comes
Phrase Comes Your Here
Phrase Comes Here Your
Phrase Here Your Comes
Phrase Here Comes Your
Comes Your Phrase Here
Comes Your Here Phrase
Comes Phrase Your Here
Comes Phrase Here Your
Comes Here Your Phrase
Comes Here Phrase Your
Here Your Phrase Comes
Here Your Comes Phrase
Here Phrase Your Comes
Here Phrase Comes Your
Here Comes Your Phrase
Here Comes Phrase Your

You can play with number combinations instead of words.