Thursday, November 27, 2008

Apache Set up Vitrual Host

Here are the configuration for Apache when setting up virtual host

NameVirtualHost *:80


ServerName dev.leoman730.com
DocumentRoot /Applications/MAMP/htdocs/dev_leoman730



ServerName ocmgt.leoman730.com
DocumentRoot /Applications/MAMP/htdocs/dev_ocmgt



Also remember to modify the hosts file accordingly in order for it to work.

Some more helpful tip can be found: Here

Set up virtual host on MAMP

1. Open your httpd.conf
This file will reside in /Applications/MAMP/conf/apache/httpd.conf .

2. Go to the bottom of httpd.conf find the vhost section, usually locates at the bottom of the file,
add virtual host like this:
<====IF PORT SET TO 8080 ==>
NameVirtualHost *:8080


ServerName dev.domain.net
DocumentRoot /Applications/MAMP/htdocs/dev_domain



ServerName test.domain.net
DocumentRoot /Applications/MAMP/htdocs/test_domain


<====IF PORT SET TO 80 ==>
NameVirtualHost *:80


ServerName dev.domain.net
DocumentRoot /Applications/MAMP/htdocs/dev_domain



ServerName test.domain.net
DocumentRoot /Applications/MAMP/htdocs/test_domain



3. Modify host file, the host file is located at:
/etc/hosts

Open the file, then add entry:
127.0.0.1 dev.domanin.net
127.0.0.1 test.domain.net

4. Restart Apache server.

NOTE:
IF YOU ARE USING PORT 8080 FOR MAMP, YOU CAN ACCESS THE SITE LIKE: http:test.domain.com:8080
IF YOU ARE USING PORT 80 FOR MAMP, YOU CAN ACCESS THE SITE LIKE: http:test.domain.com (If you cannt restar apache from MAMP after set the port 80, make sure no other apache server is using the port already)

Setting Up SVN on mac

Here's a tutorial provide information on how to set up entire svn environment for mac.
SVN SET UP

Thursday, November 20, 2008

Ajax weirness

When doing an ajax call through javascript, sometimes it may seems like nothing is happening in firebug, instead it thrown an javascript error.
One thing to check is to make sure the permission is correctly setup in the ajax script. The problem i have is that when the php script get call, it upload an image to the server, if upload directory's permission not properly set up, the weirness of this ajax call occur.

Using biwise operator to implement user access

Here's a way to use biwise operator to implement user access of special section on a site.

1. Define Constants:
PER_ADD = 1 (000001)
PERM_EDIT = 2 (000010)
PERM_DELETE = 4 (000100)
PERM_VIEW = 8 (001000)

2. Define user access level code:
EDIT => 63 (111111)
READ => 8 (000100)
NOACCESS=>0(000000)

3. Each user is associate with one or more access level code base on the section.

4. The algorithm to perform user access check is like this:
if((userAccessCode & PERM_EDIT) == PERM_EDIT){
grand access
}else{
access denial
}


How this works?
Using above example, if the user access code for a special section is defined as 63 which the binary representation is 111111, and we want to check if the user has edit permission for the section, then we can use the & biwise operator to figure it out. Sine the PERM_EDIT is define as 2 (000010), so

1 1 1 1 1 1 (63)
& 0 0 0 0 1 0 (2)
--------------
0 0 0 0 1 0 (2)

which if((userAccessCode & PERM_EDIT) == PERM_EDIT){ } will return true, so user can modify this section.

Other example, if the user access code is 8 (000100),

0 0 0 1 0 0 (63)
& 0 0 0 0 1 0 (8)
--------------
0 0 0 0 0 0 (0)

which if((userAccessCode & PERM_EDIT) == PERM_EDIT){ } will return false, so user can not modify this section.


Here's a list of possible combinations:
0 & 0 = 0
8 & 8 = 8 (Read)
63 & 8 = 8 (Read)
63 & 2 = 2 (Write)
8 & 2 = 0 (No write)