I have a function in my class (derived from this function) to generate a secure code and then a test function to update the database and print the code out onto the page. The generator function works fine on a page where it is just functionally programmed and immediately called, but once I put it into my class in CodeIgniter, it doesn't work.
Here is my generator function:
private function createSecureCode()
{
// Get 128 pseudorandom bits in a string of 16 bytes
$pr_bits = '';
$fp = @fopen('/dev/urandom','rb');
if ($fp !== false) {
$pr_bits .= @fread($fp,16);
@fclose($fp);
}
return $pr_bits;
}
Here is my test function:
public function test()
{
$query = $this->db->get("clients");
$result = "";
foreach($query->result() as $results)
{
$code = $this->createSecureCode();
$result .= $code." - ";
$this->db->where("client_id", $results->client_id);
$this->db->update("clients", array("client_secure_code" => $code, "client_active" => 1));
}
/*$query = $this->db->get("clients");
$row = $query->first_row();
print($row->client_secure_code." - ");*/
print($result);
return $result;
}