簡體   English   中英

PHP替換文件中的特定行

[英]PHP replace specific line in file

我實際上在網上找不到任何答案。 在編碼方面,我總是在網上搜索答案。 好..

我想知道如何用PHP中的其他方式更改文件中的特定行?

我有4行如下所示:

$2y$10$hashedpassword
typewar
typewarMMM36634573323
84.2xx.xxx.xxx

我最近開始研究cookie和類似的東西,並希望每當用戶登錄服務器或訪問index.php時就能夠更改cookie(第3行)。

我猜是這樣的嗎?

$user = 'typewar';
$GeneratedCookie = $user . 'MMM' . date('H', time()) * date('i', time()) * 333;
$lines = file('/path/to/identity/' . $user . '/identity.txt');
str_replace($lines[2], $GeneratedCookie . '/n');

請幫忙。

我不太確定你的情況。 請找到以下想法並進行檢查。

$user = 'typewar';
$GeneratedCookie = $user . 'MMM' . date('H', time()) * date('i', time()) * 333;
$lines = file('/path/to/identity/' . $user . '/identity.txt');
print_r($lines); 
$lines[2] = $GeneratedCookie;
print_r($lines);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM