私は安全なコードを生成するために私のクラス(thisから派生した)の関数を持っています。そして、データベースを更新してコードをページに出力するテスト関数を持っています。ジェネレータ関数は、機能的にプログラムされ、ただちに呼び出されるページ上でうまく動作しますが、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;
}
"私はCodeIgniterのクラスに入れてから動作しません。 - 実際に何が起こるか(起こらないか)? "private"として設定したので、 "createSecureCode()"は同じクラスにありますか? – Laurence
はい、両方ともクライアントモデルにあります。 $ code変数にcreateSecureCode()を呼び出すと、$ code変数は空になります –