Monday 5 December 2011

Memory Organization in 80386

The Physical memory of 80386 is organized as a sequence of bytes. Each byte is assigned a unique address that ranges from zero to a maximum of 2^(32) -1 (4 gigabytes). The logical memory of 80386 can address up to 2^(46) bytes (64 terabytes).
The two types of memory models in 80386 are


  • A "flat" address space consisting of a single array of up to 4 gigabytes.
  • A segmented address space consisting of a collection of segmants.
Both  model provides memory protection.

Flat Model
In a flat model , a programmer sees memory as a single array up to 4GB. The processor maps the 4 GB flat space onto the physical address space by the address translation mechanisms.
A pointer into this flat address space is a 32-bit ordinal number that may range from 0 to 2^(32) -1. Relocation of separately-compiled modules in this space must be performed by systems software (e.g., linkers, locators, binders, loaders)

Segmented Model
In Segmented model, address space is viewed as collection of segments. The segmented model can consist of 16,383 segments.
Applications programmers view the logical address space of the 80386 as a collection of up to 16,383 one-dimensional subspaces, each with a specified length. Each of these linear subspaces is called a segment. A segment is a unit of contiguous address space. Segment sizes may range from one byte up to a maximum of 2^(32) bytes (4 gigabytes).

A pointer in this address space consists of two parts:
  •  A segment selector, which is a 16-bit field that identifies a segment.
  •  An offset, which is a 32-bit ordinal that addresses to the byte level within a  segment. 

80386 processor: Introduction

The 80386 is an advanced 32-bit microprocessor optimised for multitasking operating systems.It is designed for applications needing very high performance.
The processor can address up to four gigabytes of physical memory and 64 terabytes (2^(46) bytes) of virtual memory.

Tuesday 1 November 2011

Fixed : window.location not working in IE6

windows.location works fine in FF. But It fails though in IE6. I tried many variations window.location, window.location.href ,window.location.href.assign ,document.location,document.location.href but nothing worked out.

After few hours of googling I found the solution. we need to add the following line to get it worked in IE 6 .


      if(window.event ) {//IE 6
            window.event.returnValue = false;
            window.location = "http://www.google.com";
            return false;
      }else {//firefox
             window.location = "http://www.google.com";
      }



Wednesday 19 October 2011

How to calculate time difference in php

We can use time() function to calculate the difference between 2 dates in PHP. The time() function returns the current time as a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT).

The below function  returns the number of minutes, hours, days and months between 2 timestamp.


    /* 
     * Minutes  =  60       seconds
     * Hour     =  3600     seconds
     * Day      =  86400    seconds 

     * Month    =  2592000  seconds
     */


function timeAgo($time) {
   //get the time difference between current time and login time
   $timeDif=time()-$time;

   // month difference

   if (($timeDif/2592000)>=1) {
       if(floor(($timeDif/2592000))==1){
           return floor(($timeDif/2592000))." month";
       }
       else {
          return floor(($timeDif/2592000))." months";
       }
    }
    //day difference
    elseif (($timeDif/86400)>=1) {
      if(floor(($timeDif/86400)) == 1){
         return floor(($timeDif/86400))." day";
      }
      else{
         return floor(($timeDif/86400))." days";
       }
    }
    //hour difference
    elseif(($timeDif/3600)>=1) {
      if(floor(($timeDif/3600)) ==1){
         return floor(($timeDif/3600))." hour";
      }
      else{
         return floor(($timeDif/3600))." hours";
      }
    }
    // minute differnece
    elseif(($timeDif/60)>=1) {
      if(floor(($timeDif/60)) ==1){
         return floor(($timeDif/60))." minutes";
      }
      else{
         return floor(($timeDif/60))." minutes";
      }
    }else {
    return "less than 1 minute";
    }
}



Tuesday 18 October 2011

How to decrypt the md5 encrypted password in PHP

md5 is supposed to be a one way encryption. But we can validate the password. First create an md5 hash of the password supplied by the user, and compare that with the encrypted password in the database.

This example shows how to change the md5 encrypted password in the database 

     $username = $_POST['user']; // get the username from the  form

     $currentpassword = $_POST['password']; // get the current password from
                                                                           the form
 
     $newpassword = $_POST['newpassword']; // get the new password from the
                                                                              form
     $hash = md5($currentpassword); // encrypt the current password supplied
                                                            by the user

     $result = mysql_query("SELECT password from Users  where
     username='username' ");  // query the database for getting password for a
                                                   the user.

     $row = mysql_fetch_array($result);

     $p=$row[password]; // get the encrypted password from the database for the
                                           user
     if($p==$hash){

           $result = mysql_query("UPDATE members set       
                           password=md5('newpassword') where username='username' ");
      } // update the new password for the user in the database in encrypted form,
            only if the encrypted current password and the password stored in the
            database are same

Monday 17 October 2011

Need to import my database - Error 1046

Issue : I am trying to import a copy of a my website sql database(developed using mysql 5) . When I try to import the backup.sql file via phpmyadmin in xampp 1.7.4, I get the following error.

MySQL said: 

#1046 - No database selected

Resolution:

For the database import, before we attempt to import the "flat" file data in, we need to goto our phpAdmin and create new database and import tables to that database.

CREATE DATABASE DATABASE_NAME


 



Thursday 13 October 2011

Installing XAMPP on Linux

XAMPP is an easy to install Apache distribution containing  Apache web server, MySQL, PHP, Perl, a FTP server and phpMyAdmin. XAMPP is  very easy to install in Linux

Installation steps
1. Download the latest binary of XAMPP from the Apache Friends Web site
    http://www.apachefriends.org/en/xampp-linux.html#374
2. Copy the zip file (xampp-linux-1.7.4(2).tar.gz)in to a folder
3. Open the terminal within the folder.
4. Login as Root.
    cluster3@cluster3-desktop ~/Public/Lekshmi $ su
    Password:
4. Untar it to /opt using the following command:

    tar xvzf xampp-linux-1.7.4.tar.gz -C  /opt

5. XAMPP is now installed in /opt/lampp folder.
6. Open the /opt/lampp folder.
7. Open the terminal in the lampp folder and login as root
8. Start the lampp server using the command

     /opt/lampp/lampp start
      
     cluster3@cluster3-desktop /opt/lampp $ su
     Password:
     cluster3-desktop lampp # /opt/lampp/lampp start
     Starting XAMPP for Linux 1.7.4...
     XAMPP: Starting Apache with SSL (and PHP5)...
     XAMPP: Starting MySQL...
     XAMPP: Starting ProFTPD...
     XAMPP for Linux started.
9. XAMPP is now up and running.
10. Open a browser and type locahost in the address bar and hit the enter key.
      You should be redirected into Xampp home page.