Monthly Archives: March 2015

Getting data from CI db query

1. All result set

$query = $this->db->query("YOUR QUERY");

if ($query->num_rows() > 0)
{
   foreach ($query->result() as $row)
   {
      echo $row->title;
      echo $row->name;
      echo $row->body;
   }
}

2. Just one row

$query = $this->db->query("YOUR QUERY");

if ($query->num_rows() > 0)
{
   $row = $query->row(); 

   echo $row->title;
   echo $row->name;
   echo $row->body;
}

Reference: CI2, CI3

How to set up recaptcha (no captcha) in PHP

3 steps to implement new recaptcha no captcha in PHP

1. Register the domain to get the keys – “site key” and “secret key”

2. include code in the page you want to show the recaptcha

a. in <head>

<script src='https://www.google.com/recaptcha/api.js'></script>

b. in <form> – exactly you want to show the recaptcha

<div class="g-recaptcha" data-sitekey="xxxxx"></div>

3. include code to check upon submission (PHP file that process the form)

// use this function to get true/false result from the submitted response
function captcha_verify($secret_key)
{
        $response =file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secret_key."&response=".$_POST['g-recaptcha-response']);
        
$response = json_decode($response, true);
        if($response["success"] === true)
        {
            return true;
        }
        return false;
    }
}