Author Archives: invtr

What a system can do?

Everytime I sit to do proposal, I come to face this question on what a system can do?

  1. Automate the process
  2. Shorten the process
  3. Centralized the data
  4. Data is at all time up-to-date
  5. Can generate more useful information

Installing SSL with WHM cPanel

Steps to install SSL using WHM (web hosting manager)

I’ve done this once, but forgot already. So I’ll keep a note for the installation for future reference.

Will update this post again soon (while I do the installation for the SSL on server).

There is a group of functions for SSL certificate installation that covers the following:

  • Generate an SSL Certificate and Signing Request
  • Install an SSL Certificate and Setup the Domain
  • Manage SSL Hosts
  • Purchase and Install an SSL Certificate
  • SSL Key/Crt Manager

Steps to install

  1. Get the CSR (certificate signing request) in WHM
    1. If not yet generate, go to SSL/TLS > Generate a SSL Certificate & Signing Request
    2. Will get CSR, RSA and certificate
    3. Can also retrieve from SSL/TLS > SSL Key/Crt Manager under “Signing Requests” column for the specified domain
  2. Active the SSL from provider (need to purchase first)
    1. Choose Apache OpenSSL and paste the CSR generated from the server
    2. Verify some email and contact information
    3. Wait for an email after submit request for SSL certificate (this will take quite some time – 5-20 minutes)
    4. Go through a verification to get the certificate (verification code sent with email)
  3. Install SSL certificate in WHM
    1. The rct (certificate got from provider)
    2. RSA generate by server
    3. CA bundle (by provider)

To renew, easiest way is to remove the host first and repeat again as new installation. But site will be down for some time during the process (after remove the host)

Error that might occur is the IP is not dedicated. If this persists, try to change IP in Account Functions > Change Site’s IP Address

PHP Data Object (PDO)

An object in PHP to manage data

PDO

  • exec
  • prepare
  • query
  • lastInsertId

PDOStatement

  • execute
  • fetch
  • fetchAll
  • fetchColumn
  • fetchObject
  • rowCount

PDOException

  • getMessage (return string)

Some sample code:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass); //establish connection
$dbh = null; //close connection
 
//insert by prepare statement
$stmt = $dbh->prepare("INSERT INTO REGISTRY (name, value) VALUES (?, ?)");
$stmt->bindParam(1, $name);
$stmt->bindParam(2, $value);
 
// insert one row
$name = 'one';
$value = 1;
$stmt->execute();
 
//get result
$stmt = $dbh->prepare("SELECT * FROM REGISTRY where name LIKE ?");
 
if ($stmt->execute(array("%$_GET[name]%"))) {
  while ($row = $stmt->fetch()) {
    print_r($row);
  }
}

2nd CNAME for blogspot

Google just introduced another security level to set custom domain for blogspot.com. Besides normal ghs.google.com to be added to the CNAME record in domain, user needs to add another 2nd unique CNAME record.

You can get the 2nd CNAME by following below steps

1. Go to blogger setting for any blog

Settings > Basic

2. Under “Publishing”, click on “Add a custom domain”
3. Click “Switch to advanced settings”
4. Enter your registered domain name
5. Click “settings instructions”

6. Choose type of domain to install.

e.g.  “On a top-level domain (www.example.com).”

7. Get the CNAME under “CNAME” subject

Add two CNAME records. For the first CNAME, where it says Name, Label or Host enter “qprm” and where it says Destination, Target or Points To enter “ghs.google.com” . For the second CNAME, enter “OKQFRCLFFBSL” as the Name and “gv-MK4QLTUM3XARQLGY4ZBLD6ZMRAERAEF72BQBZAZMNN26JVOAZ6AH.domainverify.googlehosted.com.” as the Destination. See our detailed instructions on providing CNAMEs for various registrars. If yours isn’t listed, or if you run into
other difficulties, contact your registrar directly and they can help you out.

Remove contact from google app contact list

I tried to remove a contact of a friend since he has a new email address. Few times I mistakenly sent to his old email address. But I couldn’t found where to go about to remove the old email address.

After wandering around, I found this hidden link to contact to remove a friend’s contact.

Click on the “Contact” link

Search for a contact

Click on the More > Delete contact

You are done removing a contact in your contact list.

Learn CodeIgniter

What you should do and learn

  • Download latest version of codeigniter
  • Set config/autoload.php to automatically load important and common helpers/library etc
    • helper – form, url
    • library – database
  • Good to start following tutorial under “General Topics” and “Tutorial”
  • Create a new controller (can copy from sample controller named welcome). Edit the class name, change the view to call. Class name should start with capital letter.
  • Create a new view and call from the controller
  • Change the config/routes.php to set as default controller
  • Learn how to pass data from controller to view
  • This is the way to load view, controller, helper etc
    • $this->load->view(‘aname’);
    • $this->load->helper(‘aname’);
    • $this->load->model(‘aname’);
  • Create a form in the view
    • use form_open(‘controller/function_name’) and form_close() function
  • Try pass a value via the form
    • to get data in controller use $arecord = $this->input->post(‘fieldname’);

DB Activities

  • set up DB config in config/database.php
  • set config/autoload.php to auto load database library
  • learn to use standard query and active record to insert/retrieve data from database
    • standard query – $query = $this->db->query(‘SELECT * FROM my_table’);
    • active record
      • $this->db->select(‘field1, field2’);
      • $query = $this->db->get(‘my_table’);  //use this to get all records and fields in a table.
  • retrieve the data result
  • controller to get result from model,
    • $this->load->model(‘model_name’,’avar’); //avar is variable to the model
    • function (in controller) to get the result by calling the function in model – $result = $this->avar->function_name();
    • function in model must do the query and return the result (to be retrieved by other functions from controller)
  • controller to pass the result to view as usual $this->load->view(‘view_name’, $data);
  • to loop the result set in view using foreach ($result as $list): echo $list[‘field_name’]
  • more with active record – complete CRUD and more
  • //save data to db (must load db class)
  • $data = array(
    ‘title’ => ‘My title’ ,
    ‘name’ => ‘My Name’ ,
    ‘date’ => ‘My date’
    );
    $this->db->insert(‘mytable’, $data);

Codeigniter user guide

PHP script to check no record found

If no record found for a particular condition, you can display message to the users. The code as below

1
2
3
4
5
6
7
8
$sql="SELECT * FROM user WHERE email = '$email'";  
$result=mysql_query($sql);
$num=mysql_numrows($result);
 
if ($num > 0)
  echo "found something";
else
  echo "no record found";