2012-04-23 51 views
0

以下代碼不會在Windows上的WAMP中生成輸出。不生成WAMP散列

在MAMP上正常工作。

猜測這是一個缺失的模塊或東西。

$reportHash = str_replace(
     array('+','/','='), 
     array('-','_',''), 
     base64_encode(file_get_contents('/dev/urandom', null, null, -1, 16))); 

回答

2

Windows上沒有/dev/urandom

的便攜式隨機字符串發生器或mt_rand()用於便攜式隨機數發生器使用uniqid()

+0

擊敗我吧!這是一個與mt_rand()相關的SO問題:http://stackoverflow.com/questions/9446892/php-using-mcrypt-create-iv – 2012-04-23 17:04:11

+0

即使在WAMP中? – David 2012-04-23 17:04:28

+0

@David,WAMP是一個軟件集合,可以很容易地在Windows上運行PHP,Apache和MySQL。它們將在Windows上運行,而不是在UNIX上運行。 '/ dev/urandom'是一個存在於UNIX文件系統上的文件(['file_get_contents()'](http://php.net/file_get_contents)實際上打開了文件並從中讀取文件),但是Windows上沒有這樣的文件,所以讀取會失敗。使用該文件將限制代碼到UNIX系統(例如Linux和Mac OS X)的可移植性。 – rid 2012-04-23 17:05:53