クラスに(この関数から派生した)安全なコードを生成する関数があり、次にデータベースを更新してコードをページに出力するテスト関数があります。ジェネレーター関数は、機能的にプログラムされてすぐに呼び出されるページでは正常に機能しますが、CodeIgniterのクラスに入れると、機能しません。
これが私のジェネレーター関数です:
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;
}
これが私のテスト関数です:
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;
}