Archive

Archive for the ‘php’ Category

Project CMS finished

23 October, 2009 leadamc Leave a comment

I have been very busy for the last 3 months, for building a CMS management system for The Smith Group. It contains 14 websites and an admin CMS system.

The system is built from scratch in PHP MYSQL Javascript AJAX in a linux box.

Project management nightmare:

The requirement was not full established at the beginning of the project, and Project Manager went on vacation for 8 weeks. During the 8 weeks, I hard coded all the CMS systems, and based on the website new template he gave me.  I have all the functions coded, website integrated, modified, etc etc.  But when he got back, everything I did was not he wanted.  From experience, it highly depends on  his input on this project during the process of building the system. Now that he is back, 3 weeks after, all the functions, website layout, hyper links, etc etc are changed. Until now, he still wants to change functions, although these functions are already been modified in the previous 3 weeks. But anyway, the project is getting to an end. I will responsible for future changes.

From this example, also as per project management studies, how important it is to have a fully established and fully understand requirement for any given project!!!

I learned from experience, especially this experience, that to work on a project or to start a new project, requirement study and feasibility study is very important, and also have the requirements and scale well established before the start is the key to have a successful project.

Although this Smith CMS project is finished, it has extended for an extra 2 weeks in an established 9 weeks project schedule, which is about 1/5 times more.  It is a successful project based on customer satisfaction, functionality, and so on.

Categories: CMS System, Programming, ajax, php

Please reference this blog when you find us useful.

13 October, 2009 leadamc Leave a comment

Please pass a reference or link to us if you find any useful stuff interests you on this blog. It is very important for us to prompt our blog and our company.
ICN Technologies, the name to reference.
:) Just a thought.

image uploader class (PHP)

23 September, 2009 leadamc 1 comment

~/Desktop/test.php.html

<?php
//////////////////////////////////
//////Class ImgUploader.php///////
//////Creator: leadamc ///////////
//////////////////////////////////

$uploaddir = '../group/files/';

//define a maxim size for the uploaded images in Kb
 define ("MAX_SIZE","5000");

//This function reads the extension of the file. It is used to determine if the file  is an image by checking the extension.
 function getExtension($str) {
         $i = strrpos($str,".");
         if (!$i) { return ""; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l);
         return $ext;
 }

//This variable is used as a flag. The value is initialized with 0 (meaning no error  found)  
//and it will be changed to 1 if an errro occures.  
//If the error occures the file will not be uploaded.
 $errors=0;
//checks if the form has been submitted
 if(isset($_POST['Submit']))
 {
    //reads the name of the file the user submitted for uploading
    $image=$_FILES['image']['name'];
    //if it is not empty
    if ($image)
    {
    //get the original name of the file from the clients machine
        $filename = stripslashes($_FILES['image']['name']);
    //get the extension of the file in a lower case format
        $extension = getExtension($filename);
        $extension = strtolower($extension);
    //if it is not a known extension, we will suppose it is an error and will not  upload the file,  
    //otherwise we will do more tests
 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
        {
        //print error message
            echo '<h1>Unknown extension!</h1>';
            $errors=1;
        }
        else
        {
//get the size of the image in bytes
 //$_FILES['image']['tmp_name'] is the temporary filename of the file
 //in which the uploaded file was stored on the server
 $size=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($size > MAX_SIZE*1024)
{
    echo '<h1>You have exceeded the size limit!</h1>';
    $errors=1;
}

//we will give an unique name, for example the time in unix time format
$image_name=time().'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname=$uploaddir.$image_name;
//we verify if the image has been uploaded, and print error instead
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
    echo '<h1>Copy unsuccessfull!</h1>';
    $errors=1;
}}}}

//If no errors registred, print the success message
 if(isset($_POST['Submit']) && !$errors)
 {
    echo "<h1>File Uploaded Successfully! Try again!</h1>";
 }
?>

Building CMS system for Smiths Motor Co. & Smiths Group

23 September, 2009 leadamc Leave a comment

Have been hired and custom build a CMS system for their brand new website template. Pretty much everything is blank, and I am so under paid… But anyway, I like doing it, and good at it anyway.

CMS system is up and running in no time, great work to me. MySQL PHP Ajax CSS, way it is now, gotta catch the fashion here.

I will post some sample coding examples that I gave me hard times, and all solved in the end.

Have anybody out there that does programming contracts by themselves? There are going to a lot people I think. Not a very reliable job, but makes some good money.

As for now, project getting to the end, and everything is up and running, and testing in a internal linux box. By end of this week, we will upload everything to Melbourne located data centre.

It is coding time, gotta fix some ridiculous error requests, which it is perfectly working as it is.
Leadamc

Install Apache2.2 with ssl in FREEBSD

16 March, 2008 leadamc Leave a comment

Getting Apache installed to get a web server running!

Installing Apache2.2

Make sure you update ports and then run the following commands:

# cd /usr/ports/www/apache22
# make install clean

That will install apache2.2

Configuring apache2

Lets edit the httpd.conf file:

# vi /usr/local/etc/apache22/httpd.conf

Scroll down and change the following settings. The optional settings I will put OPTIONAL before the setting:

OPTIONAL: Listen 80 – You can change this default option if you have more than one apache server running on your network
OPTIONAL: User www – Changes what user apache runs as
OPTIONAL: Group www – Changes what group apache runs as
ServerAdmin <!– var prefix = ‘ma’ + ‘il’ + ‘to’; var path = ‘hr’ + ‘ef’ + ‘=’; var addy46099 = ‘you’ + ‘@’; addy46099 = addy46099 + ‘example’ + ‘.’ + ‘com’; document.write( ” ); document.write( addy46099 ); document.write( ” ); //–> you@example.com This email address is being protected from spam bots, you need Javascript enabled to view it – change <!– var prefix = ‘ma’ + ‘il’ + ‘to’; var path = ‘hr’ + ‘ef’ + ‘=’; var addy46099 = ‘you’ + ‘@’; addy46099 = addy46099 + ‘example’ + ‘.’ + ‘com’; document.write( ” ); document.write( addy46099 ); document.write( ” ); //–> you@example.com This email address is being protected from spam bots, you need Javascript enabled to view it to your email address.
OPTIONAL: DocumentRoot “/stuff/www” – I don’t usually use the default path. I put my www documents on a seperate drive.
OPTIONAL: Directory “/stuff/www” – Change this to the same path as DocumentRoot (See above)
OPTIONAL: DirectoryIndex index.html index.html.var – add any pages you would use. For instance, add index.php if you use php pages
OPTIONAL: #CustomLog /var/log/httpd-access.log combined – I usually leave this commented unless you want to use this to track users looking at your site
OPTIONAL: ScriptAlias /cgi-bin/ “/usr/local/www/cgi-bin/” – change this to your cgi-bin path
OPTIONAL: Directory “/usr/local/www/cgi-bin”> – change this to the same path as ScriptAlias /cgi-bin above

Now lets tell apache to start:

# apachectl start

and hit Enter on your keyboard

We now need to tell Apache to run on startup. Please run the following command:

# echo ‘apache22_enable=”YES”‘ >> /etc/rc.conf

If you get no errors, apache should be running. Look at the page by opening a browser to http://localhost or replace localhost with the IP or the actual hostname of the box. If you went with the DocumentRoot defaults, You will see an apache test page until you get your site up and going. If you are behind a router or firewall, make sure you forward the apache port (Port 80) to the FreeBSD box otherwise you won’t be able to get there from here. :-)

Configuring SSL

Let’s get SSL Configured and Installed:

(FROM http://www.bsdguides.org/guides/freebsd/webserver/apache_ssl_php_mysql.php)

# mkdir /usr/local/etc/apache22/ssl.key
# mkdir /usr/local/etc/apache22/ssl.crt
# chmod 0700 /usr/local/etc/apache22/ssl.key
# chmod 0700 /usr/local/etc/apache22/ssl.crt

Create Certificate

Now, you need to understand that one server can hold multiple certificates, but only one per listening IP address. So, if your server is listening on one IP address, you can only have one certificate for the server. Follow me so far? All of your virtual domains can share the same certificate, but clients will get warning prompts when they connect to a secure site where the certificate does not match the domain name. If your server is listening on multiple IP addresses, your virtual hosts have to be IP-based — not name-based. This is something to consider when creating your certificate. :-)

Change to your root dir by typing in the following command. We want to save this configuration there as a backup.

# cd /root
# openssl genrsa -des3 -out server.key 1024

You will now be prompted to enter in a password. Write this down as you will need it later. We need to make a Certificate Signing Request (CSR):

# openssl req -new -key server.key -out server.csr

Enter your password when it asks for it. Make sure you enter your FQDN for the “Common Name” portion.

Self-signing your Certificate

You could always pay money to Verisign or Thawte for this but it costs $$$. Here is the way to do it:

# openssl x509 -req -days 365 -in /root/server.csr -signkey /root/server.key -out /root/server.crt

Now your cert is good for 365 days. If you want to make it longer, go right ahead and do so :-)

If you would like more information about SSL Certs, go to http://httpd.apache.org/docs-2.0/ssl/ssl_faq.html#aboutcerts

Now we need to copy the certs to the right place:

# cp /root/server.key /usr/local/etc/apache22/ssl.key/
# cp /root/server.crt /usr/local/etc/apache22/ssl.crt/

Now to give them the right permissions as well:

# chmod 0400 /usr/local/etc/apache22/ssl.key/server.key
# chmod 0400 /usr/local/etc/apache22/ssl.crt/server.crt

We will now want to copy the default httpd-ssl.conf from the extras folder to the Includes folder:

# cd /usr/local/etc/apache22/extra
# vi httpd-ssl.conf

Now modify the following:

DocumentRoot “/usr/local/www/data” – Change the path to your httpd.conf document root.
ServerName www.example.com:443 – Change www.example.com to your domain name.
ServerAdmin <!– var prefix = ‘ma’ + ‘il’ + ‘to’; var path = ‘hr’ + ‘ef’ + ‘=’; var addy46099 = ‘you’ + ‘@’; addy46099 = addy46099 + ‘example’ + ‘.’ + ‘com’; document.write( ” ); document.write( addy46099 ); document.write( ” ); //–> you@example.com This email address is being protected from spam bots, you need Javascript enabled to view it Change this to your email address
ErrorLog /var/log/httpd-error.log – You can leave this or comment it out.
TransferLog /var/log/httpd-access.log – You can leave this or comment it out.

Now run the following:

# apachectl stop
# apachectl start

The start means it will start in ssl mode to serve both http:// and https:// addresses. This used to be apachectl sslstart but that command has been depreciated.

The URL below includes instructions on how to remove the pass phrase prompt when apache starts

http://httpd.apache.org/docs/2.0/ssl/ssl_faq.html#removepassphrase

Configuring php for Apache

This section is pretty easy. Just run the following:

# cd /usr/ports/lang/php5
# make config

Make sure the box is checked that says Apache. If it isisn’t, put the cursor over it and then hit the Space Bar. Hit Tab and then hit Enter.

Then run the following to upgrade php5 to support Apache2.2

# make install clean
Next, we want to configure apache to use php5.

# vi /usr/local/etc/apache22/httpd.conf

and look for the first AddType section and add this to next line below the AddType section

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
Next go to DirectoryIndex and make sure index.php is part of it like so:

DirectoryIndex index.php index.html

With Apache2.2 it now wants to load an Accept Filter. If you don’t load the following module on startup, You will get an error everytime you start apache. Run the following command:

# echo ‘accf_http_load=”YES”‘ >> /boot/loader.conf
Now rather than rebooting the box, we can load the module manually by running:

# kldload accf_http
and then if you start Apache, You won’t get that error.

Now run the following command to start apache.

# apachectl stop
# apachectl start

You will now have apache with SSL and PHP support!

Special thanks to Bill from FreeBSDRocks

AJAX Coding example

22 February, 2008 leadamc Leave a comment

This coding goes to your <head></head> tags

====================================

<script type=”text/javascript”>
var request;
var dest;

function processStateChange(){
if (request.readyState == 4){
contentDiv = document.getElementById(dest);
if (request.status == 200){
response = request.responseText;
contentDiv.innerHTML = response;
} else {
contentDiv.innerHTML = “Error: Status “+request.status;
}
}
}

function loadHTML(URL, destination){
dest = destination;
if (window.XMLHttpRequest){
request = new XMLHttpRequest();
request.onreadystatechange = processStateChange;
request.open(“GET”, URL, true);
request.send(null);
} else if (window.ActiveXObject) {
request = new ActiveXObject(“Microsoft.XMLHTTP”);
if (request) {
request.onreadystatechange = processStateChange;
request.open(“GET”, URL, true);
request.send();
}
}
}

=============================

Using links to call javasripts functions

<div id=”menu”>
<table width=”240px”>
<tr><th> &nbsp;Product &amp; Services</th></tr>
<tr class=”rowA”><td>&nbsp;<span onclick=”loadHTML(‘../products/product_ajax.php?product_id=0′,’display’)”>IT/IS Consultation Service</span></td></tr>
<tr class=”rowA”><td>&nbsp;<span onclick=”loadHTML(‘../products/product_ajax.php?product_id=1′,’display’)”>Network Analysis and Assessment</span></td></ctr>
<tr class=”rowA”><td>&nbsp;<span onclick=”loadHTML(‘../products/product_ajax.php?product_id=2′,’display’)”>Business Desktop Support</span></td></tr>
<tr class=”rowA”><td>&nbsp;<span onclick=”loadHTML(‘../products/product_ajax.php?product_id=3′,’display’)”>Business Data Backup</span></td></tr>
<tr class=”rowA”><td>&nbsp;<span onclick=”loadHTML(‘../products/product_ajax.php?product_id=4′,’display’)”>Business Dedicate Server</span></td></tr>
<tr class=”rowA”><td>&nbsp;<span onclick=”loadHTML(‘../products/product_ajax.php?product_id=5′,’display’)”>Database Outsourcing</span></td></tr>
<tr class=”rowA”><td>&nbsp;<span onclick=”loadHTML(‘../products/product_ajax.php?product_id=6′,’display’)”>Software Engineering and Outsourcing</span></td></tr>
<tr class=”rowA”><td>&nbsp;<span onclick=”loadHTML(‘../products/product_ajax.php?product_id=7′,’display’)”>Computer Hardware Outsourcing</span></td></tr>
<tr class=”rowA”><td>&nbsp;<span onclick=”loadHTML(‘../products/product_ajax.php?product_id=8′,’display’)”>Business IT/IS Total Outsourcing</span></td></tr>
<tr class=”rowA”><td>&nbsp;<span onclick=”loadHTML(‘../products/product_ajax.php?product_id=9′,’display’)”>Emergency IT/IS Service</span></td></tr>
<tr class=”rowA”><td>&nbsp;<span onclick=”loadHTML(‘../products/product_ajax.php?product_id=10′,’display’)”>Temporary Link</span></td></tr>
</table>
&nbsp;<br />
&nbsp;<br />
&nbsp;<br />
</div>

==========================

And then all of them come to the AJAX  server-side function

<?php

switch($_GET['product_id']){
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
require(‘product-’.$_GET['product_id'].’.php’);

break;
default:
print(“No such category<br>”);
}

?>

===================

This is only the most basic functionality of a PHP AJAX MENU, use it at your own risk.

Job of the week Cont. Building menu system in Ajax using PHP

22 February, 2008 leadamc Leave a comment

Job of the week continue:

After a week of hard coding ICN Technologies CMS in php, it’s working so far so as expected. While the last two days being integration it to icnpro.com website. Now it’s online and good to go. There are still bugs to be fixed for example user login session not including time.

Since it’s our custom CMS system for icnpro.com, I’ve added some ajax coding. Utilizing AJAX to build a menu system. It is very efficient. As a result of the successful AJAX menu in CMS system, I’ve also added the AJAX system into the Product and Services page of the website. Try it out, I also included some AJAX PHP coding examples in the Research and Development Team website module, check it out and use it on your own risk.

ICNPro.com CMS has still more works to be done throughout it’s development life cycle. The system currently is only a prototype, more functionalities to be added in, such as adding encrypted articles, better structured coding, modification of existing articles.

User registration is not supported because of potential security risks. All users must be added by administrator (myself) into mysql database manual. User passwords are encrypted by MD5 algorithm, and no plain text is store in database. Happily we haven’t got too many users like IBM or EDS.

Regards.