Posted by admin on December-11-2009 Add Comments

How to Install MySQL Database Server on Windows XP

Go to your desktop and inside the folder you have initially created find file mysql-5.0.41.win32.zip. Extract the content of this file to the same folder on the desktop. Now go inside mysql-5.0.41-win32 folder and double click Setup.exe. Follow the steps:

Fig. 18 – Click next.


Fig. 19 – Select Custom and click next.


Fig. 20 – Click Change button to change the path of the installation.


Fig. 21 – Navigate to C:\webserver\mysql and click OK, then click next.


Fig. 22 – Click Install to start installation.


Fig. 23 – During installation a new window will pop up introducing MySQL Enterprise. Simply click next twice to continue with your installation.


Fig. 24 – Your installation is finished. You are now ready to configure your MySQL Server. Click Finish to start configuration. MySQL Configuration

Fig. 25 – On the first screen click next.


Fig. 26 – Select Detailed Configuration and click next.


Fig. 27 – Select Developer Machine and click next.


Fig. 28 – Select Multifunctional Database and click next.


Fig. 29 – Leave everything as default and click next.


Fig. 30 – Select Decision Support (DSS)/OLAP and click next.


Fig. 31 – Leave two options checked and port number as 3306 and click next.


Fig. 32 – Select Standard character Set and click next.


Fig. 33 – Select Include Bin Directory in Windows PATH and leave other options as default. Click next.


Fig. 34 – Tick Modify Security Settings and type in a password you want to use to access MySQL server, then click next.


Fig. 35 – Click Execute to apply configuration settings.


Fig. 36 Click Finish to exit configuration wizard.
The last thing you need to do is to open php.ini file located in C:\webserver\php and uncomment the line extension=php_mysql.dll by removing semicolon ; at the beginning. Save the file and close it. Restart the computer.
This way you have completed your installation and you are now ready to start developing your web applications using Apache, PHP and MySQL.
Good Luck!

Posted by admin on December-11-2009 Add Comments

How to Install PHP on Windows XP

Installing PHP on Windows XP

Go to your desktop and in the folder you initially created find file called php-5.2.3-Win32.zip.
Extract the content of this file to C:\webserver\php. Pull out all of the files from the php-5.2.3-Win32 folder and place them directly in C:\webserver\php.
Now we need to add our C:\webserver\php folder to the path of the Environment Variables.
To do this right click My Computer icon on your desktop and choose Properties. Then choose Advanced tab and click Environment Variables button (Fig. 13).

Fig. 13
Now select Path from the System variables list in the bottom part of the window and click Edit (Fig. 14).

Fig. 14
In the new window click inside the Variable value: box and press End button on your keyboard to get to the end of the path.
Now type in or copy and paste the following ;C:\webserver\php (Fig. 15). Make sure you start it with semicolon and to use back slashes.

Fig. 15
Once you have done this click OK in all of the windows until you close the System Properties window. Now you need to restart the computer.
Next step will be to find out if our PHP is working. Go to Start > Run and type cmd. In the command prompt window type php -v. You should see something like Fig. 16.

Fig. 16
We still have some tweaking to do before we finish our installation.
Go to C:\webserver\php and find file called php.ini-recommended. Rename that file to php.ini.
Open this file and make the following amendments:

  1. identify line with doc_root = and change it to:
    doc_root = C:\webserver\Apache2\htdocs
  2. identify line with extension_dir = “./” and change it to:
    extension_dir = C:\webserver\php\ext

Save and close the file.
Apache Configuration
Now we need to make sure that Apache knows where to search for php modules.
To do that first go to C:\webserver\Apache2\conf and open file httpd.conf in your text editor.
Because we will be running PHP as an Apache module which is faster and more secure option comparing to CGI binary, we will need to do the following changes to httpd.conf file:

  1. identify LoadModule section and add the following line at the top of this section:
    LoadModule php5_module “C:/webserver/php/php5apache2.dll”
  2. identify AddType section and add the following line at the top of this section:
    AddType application/x-httpd-php .php
  3. lastly place the following line somewhere within the content:
    PHPIniDir “C:/webserver/php/” – ensure you have a closing slash at the end of the path.

Save and close file. Restart Apache by going to Start > All Programs > Apache HTTP Server 2.0.59 > Control Apache Server and click Restart.
Now go to C:\webserver\Apache2\htdocs folder and select all files by pressing Ctrl + A on your keyboard. Right click on any of the selected files and choose Properties. In Attributes section of the General tab tick Hidden checkbox and click Apply and OK to close the window. This way you will only see your own files in this folder which is the root of our web server and the place where you will be setting up all your projects.
Inside C:\webserver\Apache2\htdocs create a file and give it a name phpinfo.php. Open this file with your text editor and place the following line:
<?php phpinfo(); ?>. Save and close the file.
Open your browser and type the following line in the URL:
http://localhost/phpinfo.php.
You should see now a PHP information page (Fig. 17).

Fig. 17 Now that our Apache and PHP is installed let´s move on to the next section where we will be installing MySQL.

Posted by admin on December-11-2009 Add Comments

how to Installing Apache on Windows XP

how to Installing Apache on Windows XP

This tutorial will show you how to install Apache 2.0.59, PHP 5.2.3 and MySQL 5.0.41 on machine running Windows XP.
To start with we will download all of the necessary applications which can be found at the following locations:
Apache: Apache download page
File to download: Win32 Binary (MSI Installer): apache_2.0.59-win32-x86-no_ssl.msi
PHP: PHP download page
File to download: PHP 5.2.3 zip package
MySQL: MySQL download page
File to download: Windows (x86) ZIP/Setup.EXE
Create a folder on your desktop and place all downloaded files inside of it.
Now go the the C:\ drive and create a folder with a name webserver.
This will be the folder where all of our apache, php and mysql files will be kept. Inside of this folder create another two: php and mysql.
Go to your desktop to the previously created folder and double click apache_2.0.59-win32-x86-no_ssl.msi. This will start installation of Apache web server. Follow the instructions:

Fig. 01 – Click next


Fig. 02 – Select I accept terms in the licence agreement and click next.


Fig. 03 – Click next


Fig. 04 – In the first two fields type in localhost and in the last one info@localhost. We will be installing Apache as a service which starts automatically when computer starts therefore we select Port 80. If you are about to use your web server just from time to time then you may choose Port 8080. This way you would need to start Apache manually everytime you are going to use it.


Fig. 05 – Select Custom and click next.


Fig. 06 – Because we want our server to be installed in C:\webserver click Change button to change the path of the installation.


Fig. 07 – Navigate to C:\webserver and click OK. On the next screen click next.


Fig. 08 – Now you are ready to install Apache. Click Install.


Fig. 09 – Once everything is done click Finish to exit setup.


Fig. 10 – You should now see a small Apache icon in the system tray.


Fig. 11 – In your C:\webserver folder you should notice an extra Apache2 folder has been created which stores your web server files.


Fig. 12 Now let´s see if Apache is running. Open your browser and if you were installing Apache as a service (Port 80) then type in URL http://localhost and press Enter. You should see the same page as displayed above. If you were installing Apache using Port 8080 then you would need to first start it by going to Start > All Programs > Apache HTTP Server 2.0.59 > Control Apache Server and click Start. Then in your browers´s URL type http://localhost:8080. This should open the same page in your browser.
Make sure you allow Apache access on your firewall.
Now let´s go to the next section to install PHP.

Posted by admin on December-11-2009 Add Comments

Storing multidimensional arrays in a file

In this tutorial I will show you how to store a multidimensional array in a file and how to retrieve these data. With this method you can imitate a very basic database functionality.

Step 1.
To realize this we need to implement 2 methods. One for the storing array and one which reads the file back and create an array from its content. The most important part is how to convert an array into a format which can be store easy in a file. To do this first we convert the array into a special string format. In this format we use some special characters to separate various sub-arrays and data elements. After it the saving of this string is quite easy.

So let’s try to convert the array into a special string. So I create a new function called array2string() and this function has 3 parameters. They are input array, the output string and a helper variable to store actual key value. This helper variable for the key element will be important later. In case of the last 2 parameters we will use variable references as we will call our function in a recursive way.

The theory is that we create a for each loop on the main array. If the actual data itself is again a new sub-array then the function will call itself. In this case that input array will be the actual sub-array. In case of the actual value is not an other array then we will add this data to the output string in the corresponding key-value format.

The complete code is quite short:

PHP Code:
<?php
function array2string($myarray,&$output,&$parentkey){
foreach(
$myarray as $key=>$value){
if (
is_array($value)) {
$parentkey .= $key."^";
array2string($value,$output,$parentkey);
$parentkey = "";
}
else {
$output .= $parentkey.$key."^".$value."\n";
}
}
}

?>

Don’t forget about the separator character. Select one which is not causes any problem. Now this string can be easily stored in a file. See it in a later step.

Step 2.
Now it’s time to make the reverse function as well. Let’s call it to string2array() and it needs 2 parameters. The input string which we want to convert and an array reference which will store the resulted array. First we need to divide the input string into smaller parts using the explode() function and our main separator character. After it we iterate over the resulted list and analyze it line by line. Inside this loop we divide the actual line it smaller parts again. If there is no more possibilities to divide the string even smaller values then we will add the actual value to the corresponding array element after we created that.

At the end our code looks like this:

PHP Code:
<?php
function string2array($string,&$myarray){
$lines = explode("\n",$string);
foreach (
$lines as $value){
$items = explode("·",$value);
if (
sizeof($items) == 2){
$myarray[$items[0]] = $items[1];
}
else if (
sizeof($items) == 3){
$myarray[$items[0]][$items[1]] = $items[2];
}
}
}
?>

Step 3.
As we have both important functions implemented let’s see an example how it works in the real life.
First I have created some test data. You can use this:

PHP Code:
<?php
// Create some test data
$mydb[0]['name'] = "John";
$mydb[0]['city'] = "Boston";
$mydb[0]['age']  = "32";
$mydb[1]['name'] = "Max";
$mydb[1]['city'] = "London";
$mydb[1]['age']  = "41";
$mydb[2]['name'] = "Ann";
$mydb[2]['city'] = "Bonn";
$mydb[2]['age']  = "29";
$mydb[3]['name'] = "Peter";
$mydb[3]['city'] = "Dallas";
$mydb[3]['age']  = "28";
$mydb[4]['name'] = "Martin";
$mydb[4]['city'] = "Berlin";
$mydb[4]['age']  = "22";
?>

Now we just need to call our implemented array2string() function and store the output string in a text file.

PHP Code:
<?php
// Convert the array into string
array2string($mydb,$output,$parent);

// Store the string in a file
$f1 = fopen("test.txt","w+");
fwrite($f1,$output);
fclose($f1);
?>

To read it back makes no problem.

PHP Code:
<?php
// Read the file back from the disk
$f1 = fopen("test.txt","r");
$newString = fread($f1,filesize('test.txt'));
fclose($f1);

// Convert the content back to an array
string2array($newString, $newArray);

// Print out the array
foreach ($newArray as $item) {
echo
'Name: '.$item['name'].'<br/>';
echo
'City: '.$item['city'].'<br/>';
echo
'Age: '. $item['age'].'<br/>';
}
?>

That’s it!

Download:
You can download an ArrayHandler script: http://www.ziddu.com/download/7236479/ArrayHandler.zip.html

Posted by admin on December-11-2009 Add Comments

How to execute PHP with cron

How to execute PHP with cron

Every now and then you will run across a task that needs to be executed through PHP however this task cannot or should not be ran by a visitor opening a webpage (such as a maintanance or caching script). The only way to run these scripts would be to do it manually as an administrator or to do it automatically using cron.
Manually sucks which is why I wrote this tutorial. Specifically this will target users of cPanel installations (gotta love shared hosting). All cPanel installs that I have used have cron as an option. When you log into cPanel there should be an option called crontab or Cron Jobs or any other such thing. Clicking this option brings up the cron jobs window.
On my install I am given the choice between Standard and Advanced (Unix Style) Cron settings. Standard makes the task more easier and offers the same amount of control, so lets press Standard.
You are given two sections to enter a cron job. If you need more, just fill in the first two and more will become visible when you save your settings. You can set all sorts of options concerning when the script will run. You can run it from every minute to ever year, controling what times down to the second that the script is executed.
The command that you run is the fun part. In my install I enter the absolute path to the script (/home/ACCOUNT/public_html/script.php). Inside of the script I have added the line:

Code:
#!/usr/bin/php -q

This will run php in command line mode when the script is run (you may need to change the path to your PHP binary). Finally, you will need to chmod 755 your php file so that it can be executed.
And there you have it. Your script will be run automatically. If you don’t want the script to be executed by a person by typing in the URL, drop it into a folder and change .htaccess settings to nobody can open the file. While debugging your script (and even making sure that it is ran at all) you may want to have output saved to a log file and execute the script manually.

Posted by admin on December-11-2009 Add Comments

Generating random passwords

Generating random passwords

It becomes practical and more useful if the tutorial is written in the form of a funtction. This function will hopefully work anywhere.
The basic idea behind this random password is that it will give a different password every time it is called. This can only be done by using the time as the main core input. So we will start of by defining a PHP function which will generate this password for us. There will be one input from the user, the length of the password. When the function will be called, it will return a random password of characters ranging from 0-32 depending on the length given (alphabets and numbers).
Here is the complete function:

PHP Code:
<?php
function randomPassword($length){

$pass = md5(time());
$pass = substr($pass, 0, $length);
return
$pass;
}
?>

The above function is pretty straight forward. The first line defines a function called “randomPassword” which takes a parameter ‘length’. The next line uses the built-in PHP function MD5(). MD5 function returns the hash of the input given. Here we give MD5 the time as input. The time() function returns the timestamp. Remember that the timestamp will always be different because the date is always changing (here date includes time and seconds). So basically when we give the MD5 function the latest timestamp, it generates the hash for that specific instant, which is also always different because of the ever changing time.
Next we substr the password returned. Substr is used for returning some specific length of a given string. For example, the substr used here will return the initial string of the password of the length that the user will give.
The last line of code returns the password randomly generated.
You can use the function the following ways:

PHP Code:
<?php
echo randomPassword(15);
//or
$password = randomPassword(15);
?>

The above code will return something like 1b415353bde123a
Enjoy the tutorial

Posted by admin on December-11-2009 Add Comments

Looping Statements in PHP

In programming it is often required to repeat a block of code for a given number of times or until a certain condition is not true. For this, we use looping statements. PHP has two major looping statements (FOR and WHILE).

In common practice, FOR loop is mostly used when we need to loop a code for specific number of times. Whereas WHILE loops are best used when we are using conditions and number of loop is not of primary priority.

THE WHILE LOOP

As said above, the while statement executes a block of code until the condition isn’t fulfilled.
Here is the syntax of while loop.

PHP Code:
while (condition){
code needed to loop;
}

The above code between { } will be executed until the condition turns to false.

Here is a proper PHP example.

PHP Code:
<?php
$i
= 0;
while (
$i <= 10){
echo
"The number is ". $i . "<br/>";
$i++;
}
?>

The above program will show output Something like.

The number is 0
The number is 1
The number is 2
…and so on.

it will show 11 outputs, from 0 to 10.

THE DO WHILE LOOP

This loop is almost the same as the WHILE loop except that it executes the code atleast once before the condition

is checked. The reason for this is that the condition statement is written at the end.
Here is a DO WHILE loop syntax.

do{
code needed to loop;
}while (condition);

if we want to write the same above program with DO WHILE

PHP Code:
<?php
$i
= 0;
do{
echo
"The number is " . $i . "<br/>";
}while (
$i <= 10);
?>

The above code will give the same output.

THE FOR LOOP

As mentioned above, the FOR loop is mostly used when we know how many times we need to loop the code. FOR loop is also known as definite loop. FOR loop is prefered by most programmers because its more convenient to use. The

syntax of FOR loop is given as follows.

PHP Code:
for (initialization; condition; increment){
code needed to loop;
}

FOR loop takes three arguments separated by ( semicolons. Although the required argument is the condition, the other two are optional.

The initialization argument is a variable which we use for incrementation/decrementation.
The condition is the expression which is evaluated everytime the code is executed and the code loops if the condition is true.
The increment or decrement updates the counter variable.

Given below is a PHP example.

PHP Code:
<?php
for ($i = 0; $i <= 10; $i++){
echo
"The number is " . $i . "<br/>";
}
?>

Next Comes the FOREACH Loop

THE FOREACH LOOP

This is basically a variation of the FOR loop and allows to iterate over array elements. The two different

versions of the Foreach loop are written below.

PHP Code:
foreach (array as value){
code needed to loop;
}
PHP Code:
foreach (array as key => value){
code needed to loop;
}

given below is a PHP based example.

PHP Code:
<?php
$num
= array('1', '2', '3');
foreach (
$num as $value){
echo
"Num " . $value . "<br/>";
}
?>

Foreach’s different type is more useful.

PHP Code:
<?php
$num
= array('1' => 'One', '2', => 'Two');
foreach (
$num as $key => $value){
echo
"Num " . $key . " is also called " . $value . "<br/>";
}
?>

In the above example, the key for each element is placed in the $key variable and its corresponding value in $value.

Although, Foreach construct does not operate on the the array itself, but rather on a copy of it. This means that what ever you change or manipulate of the $value, it wouldn’t effect the orignal array.

Break and Continue Statements

These statements are not used that often. Although they are sometimes really useful when saving some resources.
As the statements imply, Break is used to break the loop and continue is used to jump to the next iteration without executing the code beneath it.

Two examples are written below.

PHP Code:
<?php
for ($i = 0; $i <= 10; $i++){
if(
$i==5){break;}
echo
"The number is " . $i . "<br/>";
}
?>

The above program will break the loop when $i = 5;
it will show previous outputs.

Below is an example of continue.

PHP Code:
<?php
for ($i = 0; $i <= 10; $i++){
if(
$i==5){continue;}
echo
"The number is " . $i . "<br/>";
}
?>

The above program will skip the loop when $i = 5; It will show the prevous and next values.

I hope this tutorial becomes handy to those who are new to PHP.

Enjoy

Posted by admin on December-11-2009 Add Comments

PHP Login script tutorial

PHP Login script tutorial

Overview In this tutorial create 3 files
1. main_login.php
2. checklogin.php
3. login_success.php

Step
1. Create table “members” in database “test”.
2. Create file main_login.php.
3. Create file checklogin.php.
4. Create file login_success.php.
5. Create file logout.php

1- Create table “members”

Code:
CREATE TABLE `members` (
                                                `id` int(4) NOT NULL auto_increment,
                                                `username` varchar(65) NOT NULL default '',
                                                `password` varchar(65) NOT NULL default '',
                                                PRIMARY KEY  (`id`)
                                                ) TYPE=MyISAM AUTO_INCREMENT=2 ;
                                               --
                                                -- Dumping data for table `members`
                                                --
                                               INSERT INTO `members` VALUES (1, 'john', '1234');

2- Create file main_login.php
View In Browser

HTML Code:
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="text" id="mypassword"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

3- Create file checklogin.php

PHP Code:
<?php
$host
="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from  form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched  $myusername  and $mypassword,  table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo
"Wrong Username or Password";
}
?>

4- Create file login_success.php

// Check if session is not registered , redirect back to main page.
// Put this code in first line of web page.

PHP Code:
<?
session_start
();
if(!
session_is_registered(myusername)){
header("location:main_login.php");
}
?>

<html>
<body>
Login Successful
</body>
</html>

5- Logout.php

If you want to logout, create this file

// Put this code in first line of web page.

PHP Code:
<?
session_start
();
session_destroy();
?>

6- For PHP5 User – checklogin.php

PHP Code:
<?php
ob_start
();
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Define $myusername and $mypassword
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched  $myusername  and $mypassword,  table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
header("location:login_success.php");
}
else {
echo
"Wrong Username or Password";
}
ob_end_flush();
?>

7- Encrypting Password – Make your Login More Secure

Posted by admin on December-11-2009 Add Comments

Simple Ad Rotation Script

Overview

In this script (very easy script), we have 3 ads for rotation
first ad we want it to display 70%
second ad we want to display 20%
and the last one we want to display 10%

What to do

1. Random number 1-100
- if result = 1-70 (we have opportunity to display ad 1, 70%)
- if result = 71-90 (we have opportunity to display ad 2, 20%)
- if result = 91-100 (we have opportunity to display ad 3, 10%)

Example

In this script use rand(1, 100); to random number between 1 -100 and keep result in variable name “$result_random” if result = 85 ad 2 will display.

############### Code

PHP Code:
<?php

// random number 1 - 100
$result_random=rand(1, 100);

// if result less than or equal 70, display ad 1 (70%)
if($result_random<=70){
echo
"Display ad1";
}

// if result less than or equal 90, display ad 2 (20%)
elseif($result_random<=90){
echo
"Display ad2";
}

// if result less than or equal 100, display ad 3 (10%)
elseif($result_random<=100){
echo
"Display ad3";
}

?>

Posted by admin on December-11-2009 Add Comments

Get adsense stats from PHP

Get adsense stats from PHP

Why not let your own script fetch the statistics directly from google adsense reporting site? It’s always much easier to have the data locally in your own database, and then create scripts to display the stats in the way you are interested in.
I will now give you the code that collects the present stats from adsense, for any channel you specify. Because I also love to work with databases, we will store the results in mysql.
The basics behind the script is that you choose what channels you want to fetch stats for, and then you let your script do that as often as you which. You can schedule this script with crontab or something similar as often you which. Don’t do it more often than every 15 minutes, because I have heared something from google that you are not allowed to script things mroe often against adsense …
Here’s what to do:

  1. Login to adsense and click on “advanced reports”. Create channels if you don’t have any yet, because this script shows stats for separate channels.
  2. This part might be the most complicated, but still very easy. “View source” for the page and search for select name=”reportId”. Scroll further out on that row in the source and look for your channel names. You will find something similar to this Cholesterol-week . Write down the number and the name on a paper or somewhere. Do this for every channel you want to track.
  3. Create a database and assign a user with a password for that.
  4. Run this sql code:
    Code:
    CREATE TABLE `adsense` (
    `id` int(11) NOT NULL auto_increment,
    `channel` varchar(50) NOT NULL,
    `reportedWhen` datetime NOT NULL,
    `impressions` int(11) NOT NULL,
    `clicks` int(11) NOT NULL,
    `rate` decimal(10,3) NOT NULL,
    `cpm` decimal(10,3) NOT NULL,
    `earnings` decimal(10,3) NOT NULL,
    PRIMARY KEY (`id`)
    )
  5. Save the file you see in the blue box below as adsense.php or similar. Look at the first lines where you need to fill in your details. Both for your adsense account and your db details.
  6. In the file you need to enter all channelId’s and channelNames in the array. Just increase that array if you have more channels!

I have not created any script to display the stats yet, but that might come in the future :-) For now, enjoy the script and let me know if you like it!
Here is the script:

PHP Code:
<?
// Change things from here!!!
$adsenseUsername = "yourname@yourcompany.se";
$adsensePassword = "yourpassword";

$dbHostname = "localhost";
$dbUsername = "dbUsername";
$dbPassword = "dbPasswd";
$dbName = "theDbName";

$reports = Array("1234" => "channel1",
"56215" => "channel4",
"35507" => "channel3");
// Stop changing things here!!!

$adsenseCookie = "adsenseCookie.txt";

// Google time
putenv('TZ=US/Pacific');
$now = date("Y-m-d H:i:s");

$dbLink = mysql_pconnect($dbHostname, $dbUsername, $dbPassword) or die('Could not connect to database: '.$dbHostname);
mysql_select_db($dbName, $dbLink) or die('Could not find database: '.$dbName);

// Handle every report separately
foreach($reports as $id => $name)
{
$result = getAdsenseReport($id);
logChannel($name, $result, $now);