-1

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

}
4

1 に答える 1

1

問題は、Codeigniter が index.php で行う再ルーティングです。

したがって、「$fp = @fopen('/dev/urandom','rb');」失敗しています - 間違ったディレクトリを検索するためです:

/home/public_html/index.php/dev/urandom

しかし、あなたのファイルは保存されていると思います:

/home/dev/urandom

したがって、次のようにする必要があります。

$fp = @fopen('../../dev/urandom','rb')

ただし、必要に応じてサーバー/セットアップをテストして調整する必要があります

于 2012-05-11T15:19:06.210 に答える