2013-11-02 28 views
0

我最近使用PHP在Visual Basic中創建了一個聊天應用程序。PHP |在線記事本

我用這個代碼:

<?php 
$msg = $_GET['w']; 
$logfile= 'Chats.php'; 
$fp = fopen($logfile, "a"); 
fwrite($fp, $msg); 
fclose($fp); 
?>  

現在我想做一個在線記事本。 我想要做的是在Visual Basic中創建一個唯一的ID。 這個唯一的ID必須是他的文件名。 我對PHP不太擅長,所以我想知道的是:

我想讓唯一ID成爲「註釋」的文件名。 像: $logfile= '{uniqueID.php}';

每當用戶打開程序,它會打開他的uniqueID.php文件,他可以編輯在我的計劃。

長話短說(TL; DR)

  • 程序生成UNIQUEID
  • UNIQUEID將是一個新的文件; {uniqueID} .php
  • 在下一次打開時,它將檢查他/她的{uniqueID} .php是否存在,否則它將創建一個新的。

我知道這不是很安全,但它是爲我自己學習的東西。

回答

0

這應該讓你開始:

$file = uniqid(true).'.php'; // generate unique filename 
if(!file_exists($file)) { // if filename doesn't exist 
    file_put_contents($file, 'New user'); // write something to the file 
} 
+0

謝謝,但是,我想的UniqueID(這是一個HWID)在我的計劃是uniqueid.php的名稱。 我希望你能幫上忙。 – user2947423

+0

@ user2947423:你如何在你的PHP腳本中獲得這個'HWID'? – 2013-11-02 10:33:52