Tuesday, October 12, 2010

Set subdomain host IP

1. Create a Subdomain.

You can create your subdomain from your domain control panel. After create the subdomain you can forward the subdomain to the IP.

Say you have a domain www.abser.com

You make a subdomain  sd.abser.com


2. Add Host for the Subdomain.

After create the subdomain go to add host option to your control panel.

add your prefered IP as the host IP. You may add many IP for a single Host.

Say you want to add the IP 120.12.14.199 as the Host of sd.abser.com.

Put the IP to the Host IP field.


3. Create Virtual host to your Host server.

see the virtual host section to know how to add a virtual host.



...................
.................

Monday, October 11, 2010

Disable Indexing in Apache

The simple and easiest way to disable indexing in apache is adding following code to the httpd.conf/apache.conf(which is available in your server)

Add following code below of the httpd.conf/apache.conf file


<Location />
Options -Indexes
</Location>

Cheers.

Sunday, October 10, 2010

10.10.10 the Binary Day

Today is the 10th October of 2010. 10.10.10.  So many couple world wide getting married today to make the marriage Historical. This combination  of day will never came again.

So let cheer on the day.

Friday, October 8, 2010

Creating Name and IP Based Virtual hosts

We have already seen the apache2 installation in debian.If you miss that check here
After installtion we need to configure virtual hosts to host multiple websites in debian hosting server.

Basics Of Virtual Hosts

Using virtual hosts, host several domains with a single web server. In this way, save the costs and administration workload for separate servers for each domain. There are several options regarding virtual hosts:
  • Name-based virtual hosts
  • IP-based virtual hosts
  • Operation of multiple instances of Apache on one machine

Name-Based Virtual Hosts

With name-based virtual hosts, one instance of Apache hosts several domains. You do not need to set up multiple IPs for a machine. This is the easiest, preferred alternative. Reasons against the use of name-based virtual hosts are covered in the Apache documentation.
Configure it directly by way of the configuration file /etc/apache2/ sites-available/filename(by default we have default name file take this as reference and create new file). To activate name-based virtual hosts, specify a suitable directive. NameVirtualHost *. * is sufficient to prompt Apache to accept all incoming requests. Subsequently, configure the individual hosts:

<VirtualHost *>
    ServerName www.example.com
    DocumentRoot /home/www/htdocs/example.com
    ServerAdmin webmaster@example.com
    ErrorLog /var/log/apache2/www.example.com-error_log
    CustomLog /var/log/apache2/www.example.com-access_log common
</VirtualHost>
 
<VirtualHost *>
    ServerName www.myothercompany.com
    DocumentRoot /home/www/htdocs/myothercompany.com
    ServerAdmin webmaster@myothercompany.com
    ErrorLog /var/log/apache2/www.myothercompany.com-error_log
    CustomLog /var/log/apache2/www.myothercompany.com-access_log common
 </VirtualHost>
 
A VirtualHost entry must also be configured for the domain originally hosted on the server (www.example.com). In this example, the original domain and one additional domain (www.myothercompany.com) are hosted on the same server.

Just as in NameVirtualHost, a * is used in the VirtualHost directives. Apache uses the host field in the HTTP header to connect the request to the virtual host. The request is forwarded to the virtual host whose ServerName matches the host name specified in this field.

For the directives ErrorLog and CustomLog, the log files do not need to contain the domain name. Here, use a name of your choice.

ServerAdmin designates the e-mail address of the responsible person that can be contacted if problems arise. In the event of errors, Apache gives this address in the error messages it sends to clients.

IP-Based Virtual Hosts

This alternative requires the setup of multiple IPs for a machine. In this case, one instance of Apache hosts several domains, each of which is assigned a different IP. The following example shows how Apache can be configured to host the original IP (192.168.1.10) plus two additional domains on additional IPs (192.168.1.20 and 192.168.1.21). This particular example only works on an intranet, because IPs ranging from 192.168.0.0 to 192.168.255.0 are not routed on the Internet.

Configuring IP Aliasing

For Apache to host multiple IPs, the underlying machine must accept requests for multiple IPs. This is called multi-IP hosting. For this purpose, IP aliasing must be activated in the kernel.

Once the kernel has been configured for IP aliasing, the commands ifconfig and route can be used to set up additional IPs on the host. These commands must be executed as root. For the following example, it is assumed that the host already has its own IP, such as 192.168.1.10, which is assigned to the network device eth0.

Enter the command ifconfig to find out the IP of the host. Further IPs can be added with commands like the following:

/sbin/ifconfig eth0:0 192.168.1.20
/sbin/ifconfig eth0:1 192.168.1.21
 
All these IPs are assigned to the same physical network device (eth0).

Virtual Hosts with IPs

Once IP aliasing has been set up on the system or the host has been configured with several network cards, Apache can be configured. Specify a separate VirtualHost block for every virtual server:

<VirtualHost 192.168.1.20>
    ServerName www.myothercompany.com
    DocumentRoot /home/www/htdocs/myothercompany.com
    ServerAdmin webmaster@myothercompany.com
    ErrorLog /var/log/apache2/www.myothercompany.com-error_log
    CustomLog /var/log/apache2/www.myothercompany.com-access_log common
</VirtualHost>
 
<VirtualHost 192.168.1.21>
    ServerName www.anothercompany.com
    DocumentRoot /home/www/htdocs/anothercompany.com
    ServerAdmin webmaster@anothercompany.com
    ErrorLog /var/log/apache2/www.anothercompany.com-error_log
    CustomLog /var/log/apache2/www.anothercompany.com-access_log common
</VirtualHost>
 
VirtualHost directives are only specified for the additional domains. The original domain (www.example.com) is configured through its own settings (under DocumentRoot, etc.) outside the VirtualHost blocks.
 Multiple Instances of Apache
With the above methods for providing virtual hosts, administrators of one domain can read the data of other domains. To segregate the individual domains, start several instances of Apache, each with its own settings for User, Group, and other directives in the configuration file.

In the configuration file, use the Listen directive to specify the IP handled by the respective Apache instance. For the above example, the directive for the first Apache instance would be:

Listen 192.168.1.10:80
For the other two instances:
Listen 192.168.1.20:80
Listen 192.168.1.21:80
In Apache2 to configure virtual hosts there are two important files i.e
/etc/apache2/sites-available and  /etc/apache2/sites-enabled/
We need to create symlink between these two folders for each virtual host.
Example for name based virtual host in debian:-
Apache 2.0, the default site is instead the first file (in alphabetical order) in the /etc/apache2/sites-enabled directory. After initial installation, there will be a symlink from 000-default in this directory to /etc/apache2/sites-available/default. As you can see from this, Apache 2.0 offers another level of abstraction in the Virtual Hosts by recommending putting the actual files in /etc/apache2/sites-available and then symlinking from there to /etc/apache2/sites-enabled. I would recommend following this convention, but it's not mandatory. In our example above, we would create two files, /etc/apache2/sites-available/default and /etc/apache2/sites-available/example.com. Our /etc/apache2/sites-available/default file would look like this:
NameVirtualHost *
<VirtualHost *>
ServerName incorrect.com
DocumentRoot /home/www/html/default
</VirtualHost>
And our /etc/apache2/sites-available/example.com would look like this:
<VirtualHost *>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /home/www/html/example.com/html
CustomLog logs/www.example.com-access_log common
</VirtualHost>
We would then create symlinks to the /etc/apache2/sites-enabled directory with the ln -s
command: ln -s /etc/apache2/sites-available/example.com /etc/apache2/sites-enabled/example.com.

Now we have our Virtual Hosts configured, it's time to test. To start Apache 2, type /etc/init.d/apache2 start and fire up a browser and head to www.example.com
Example for IP based virtual host in debian:-
 /etc/apache2/sites-available/example.com would look like this:
<VirtualHost 192.168.1.20>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /home/www/html/example.com/html
CustomLog logs/www.example.com-access_log common
</VirtualHost>
We would then create symlinks to the /etc/apache2/sites-enabled directory with the ln -s
command: ln -s /etc/apache2/sites-available/example.com /etc/apache2/sites-enabled/example.com.

Now we have our Virtual Hosts configured, it's time to test. To start Apache 2, type /etc/init.d/apache2 restart and fire up a browser and head to www.example.com

Tuesday, September 28, 2010

Zend Framework: Multiple Check Box Handling

Here I will try to describe how to handle multiple check box with Zend Form

Below is the Form from/user.php
<?php
class Form_User extends Zend_Form
{
    public function __construct($options = null)
    {
        parent::__construct($options);
      
        $this->setName('User_Form');
       
        $user_id = new Zend_Form_Element_Text('user_id');
        $user_id->setLabel('User ID')
                  ->setRequired(true)
                  ->addValidator('NotEmpty');

      
        ..................................
        ....................................
        ....................................

        $area = array(

                            'index' => 'Home Page',
                            'admin' => 'Admin Home',
                            'agent' => 'Agent Contorl',
                            'user' => 'User Contorl',
                            'cdist' => 'Card Distribution',
                            'cardsell' => 'Card Sell',
                            'manualmt' => 'Manual Money Transfer',
                            'moneydelivery' => 'Money Delivery',
                            'transactionmonitor'    => 'Transaction Moniitor',
                            'adminreport'   =>  'Admin Report',
                            'agentreport'   =>  'Agent Report',
                            'customercare'   =>  'Customer Care',

);

$privileges = new Zend_Form_Element_MultiCheckbox('privileges');

$privileges->setLabel("Select Previliges");
            foreach($area as $prev => $p)
            {
                $privileges->addMultiOption($prev,$p);
            }

        $user_photo = new Zend_Form_Element_File('user_photo');
        $user_photo->setLabel('Photo');
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Save Data')
                 ->setAttrib('class', 'button')
        ;
       
         $this->addElements(array(
                $user_type,
                $agent_id,
                $user_id,
                .........
                $privileges,
                $submit));

    }
}


Now The Controller UserController.php


class UserController extends Zend_Controller_Action
{

    public function init()
    {
     /    }

       public function addAction()
    {
        // action body
       
        $this->view->headTitle('Add New User', 'PREPEND');
        $form = new Form_User();
        $this->view->form = $form;
      
        if ($this->getRequest()->isPost()) {
       
        $formData = $this->getRequest()->getPost();
        if ($form->isValid($formData)) {
        //$sp = implode(",",$privileges);
        $user_photo = ($form->getValue('user_photo')) ? $form->getValue('user_photo') : "";

        $data = array(
            'user_type' => $form->getValue('user_type'),
            'agent_id' => $form->getValue('agent_id'),
            'user_id' =>strtolower($form->getValue('user_id')),
           ..............................
.................................
            'privileges' => serialize($form->getValue('privileges')),
            'user_status' => $form->getValue('user_status'),
            'user_photo' => $user_photo,
        );

      
        $user = new Model_DbTable_Userinfo();

        $user-> addUser($data);
        $this->_redirect('/user/');

        } else {
            print_r($formData);
            $form->populate($formData);
        }
        }
    }



The Model to Do the database action

class Model_DbTable_Userinfo extends Zend_Db_Table_Abstract
{
    protected $_name = 'user_info';

       public function addUser($data)
    {
       
        $this->insert($data);
    }
}









To edit the Multiple check box value do as follows in Edit action

public function editAction()
    {
        // action body
        $sess = new Zend_Session_Namespace('uri');

        $this->view->title = "Edit User";
        $this->view->headTitle($this->view->title, 'PREPEND');
        $form = new Form_User();
        //$form->user_id->setAttrib('readonly','true');
        $form->removeElement('user_id');
        $user_id = new Zend_Form_Element_Hidden('user_id');
        $form->addElement($user_id);
        $this->view->form = $form;

        if ($this->getRequest()->isPost()) {
        $formData = $this->getRequest()->getPost();
        if ($form->isValid($formData)) {
        $user_id = $form->getValue('user_id');
        $agent_id = $form->getValue('agent_id');
        $user_photo =  $form->user_photo->getFileName('user_photo',false);

        if(!empty($user_photo))
            {
        $data = array(
            'user_type' => $form->getValue('user_type'),
            'agent_id' => $form->getValue('agent_id'),
            'user_pass' => $form->getValue('user_pass'),
            'user_name' => $form->getValue('user_name'),
            'user_address' => $form->getValue('user_address'),
            'user_contact' => $form->getValue('user_contact'),
            'user_email' => $form->getValue('user_email'),
            'privileges' => serialize($form->getValue('privileges')),
            'user_status' => $form->getValue('user_status'),
            'user_photo' => $form->getValue('user_photo'),
        );
            }
    else
        {
        $data = array(
            'user_type' => $form->getValue('user_type'),
            'agent_id' => $form->getValue('agent_id'),
            'user_pass' => $form->getValue('user_pass'),
            'user_name' => $form->getValue('user_name'),
            'user_address' => $form->getValue('user_address'),
            'user_contact' => $form->getValue('user_contact'),
            'user_email' => $form->getValue('user_email'),
            'privileges' => serialize($form->getValue('privileges')),
            'user_status' => $form->getValue('user_status'),
        );
        }
        $user = new Model_DbTable_Userinfo();
        $user->updateUser($data,$user_id);
        $this->_redirect($sess->req_uri);
        } else {
        $form->populate($formData);
        }
        }
        else {
        $user_id = $this->_getParam('user_id', 0);
        $user = new Model_DbTable_Userinfo();
        $user_data = $user->getUser($user_id);
        $form->populate($user_data);
        $prev = unserialize($user_data['privileges']);
        $form->privileges->setValue($prev);
        }
    }





Hope Thats help you.

Tuesday, September 7, 2010

How to detect if the user is logout in php?

You cannot detect when a user closes their browser or navigates off your site with PHP, and the JavaScript techniques of doing so are so far from guaranteed as to be useless.
Instead, your best bet is most likely to store each user's last activity time.
  • Create a column in your user table along the lines of 'last_activity'.
  • Whenever a user loads a page, update their last_activity to the current time.
  • To get a list of who's online, just query the database for users with last_activity values more recent than 10/20/whatever minutes ago.

Source: http://stackoverflow.com/questions/887919/how-to-detect-if-the-user-is-logout-in-php

Jpgraph and Zend Framework: The image “ ” cannot be displayed, because it contains errors

Problem: My Below Code failed to produce Jpgraph Graph and give the above Error.

set_time_limit(0);
        require ("jpgraph/jpgraph.php");
        require ("jpgraph/jpgraph_pie.php");
        require ("jpgraph/jpgraph_pie3d.php");

        // set the directory where images are cached by JpGraph
        //$jpgcache = APACHE_CACHE_DIR;

        $tran =  new Model_Report();
        $result = $tran->all_transaction_req();

        foreach($result as $row)
        {
        $level[]=$row['tran_req_date'];
        $data[]=$row['amount'];
        }
        //print_r($data);
        //exit;
        $graph_name = 'chart.png';
        $graph = new PieGraph(500,400,"auto");
        $graph->SetShadow();

        // Set A title for the plot
        $graph->title->Set("Transaction Statistics");
        $graph->title->SetFont(FF_VERDANA,FS_BOLD,12);
        $graph->title->SetColor("darkblue");
        $graph->legend->Pos(0.0,0.1,"right","top");


        // Create pie plot
        $p1 = new PiePlot3d($data);
        $p1->SetTheme("sand");
        $p1->SetCenter(0.4);
        $p1->SetAngle(45);
        $p1->value->SetFont(FF_ARIAL,FS_NORMAL,12);
        $p1->SetLegends($level);
        #$p1->SetLabels($level);
        $p1->SetLabelMargin(5);
        $p1->SetLabelPos(0.9);


        $graph->Add($p1);

        header ("Content-type: image/png" );
        $graph->Stroke();
        


Sloution: add exit; after  $graph->Stroke();
       .......
       ........
       $graph->Stroke();
       exit;


Source: Internet

Monday, September 6, 2010

How to Turn off Form AutoCompletion

We can off the Auto Completion in web form by following way.

1. Set autocomplete="off" in input box.


<input type="text" name="cc" autocomplete="off" />
 
 
2.  Set autocomplete="off" in Form Tag.
 
 
3. The Best way I prefere
First page ( HTML Form ) : 

<form method="post"> 
<input type="hidden" name="username" value="random1"> 
<input type="hidden" name="password" value="random2"> 
Username: <input type="text" name="random1" value=""><br />
Password: <input type="password" name="random2" value="">
</form>

Where "random1" and "random2" are random names generated, you can use in combination with unix time.

Second page ( PHP output ) :
<?php
if ( isset($_POST['username'], $_POST['password']) && isset($_POST[$_POST['username']], $_POST[$_POST['password']]) ) { echo 'Username: '.$_POST[$_POST['username']].'<br />'. 'Password: '.$_POST[$_POST['password']]; }
?> 


Sourece: Web Search