《php基础教程》——4文件和目录 学习总结
一、写入文件:
$fp = fopen(filename, mode);
mode 为打开文件方式比如 ‘a+’表示读写文件,文件不存在则创建,新数据主加到文件尾部
fwrite($fp,写入内容);
fclose($fp);
二、锁定文件:当有多个用户同时对文件操作时保证不出现冲突
fclock($fp, 锁定类型); //锁定类型包括写入独享、读取共享……
三、读取文件:
$data = file('文件路径');
将读取的数据放到data数组内,每个元素为文件的一行。
编码测试:ws.php:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>test</title><base> <?phpif (isset($_POST['submitted'])) { if (!empty($_POST['quote']) && ($_POST['quote'] != "enter your quotation here")){//Write the data to file. $fp = fopen('../test.txt','a+'); flock($fp, LOCK_EX);// lock the file fwrite($fp, $_POST['quote']); flock($fp, LOCK_UN);// unlock fclose($fp); //read the file's content to an array $data: $data = file('../test.txt'); print '<p style = "color: red;"> data[0]:\n ' .$data[0]. ''; } else{ print 'please enter your quotation'; }}?>
This is the foot of the document
测试裁图:
起始:
结果:
五、处理文件上传:
1.form标签必须包含:enctype="multipart/form-data",表单必须用post方法
2.必须添加一个隐藏输入框,建议浏览器最大上传文件大小(以字节计)
3.创建表单字段
代码测试:ws.php:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>test</title><base> <?phpif (isset($_POST['submitted'])) { if (move_uploaded_file($_FILES['thefile']['tmp_name'],"../uploads/{$_FILES['thefile']['name']}")){ print '<p>your file is upload!'; } else{ $errors = $_FILES['thefile']['error']; print $errors; }}?>
This is the foot of the document
六、目录
1.导航目录:
查找目录中所有内容:scandir();
eg: $stuff = scandir('目录名');//函数返回一个数组,包含目录中的文件和目录,复制给$stuff
2.创建目录:
mkdir( '路径名' );

絕對會話超時從會話創建時開始計時,閒置會話超時則從用戶無操作時開始計時。絕對會話超時適用於需要嚴格控制會話生命週期的場景,如金融應用;閒置會話超時適合希望用戶長時間保持會話活躍的應用,如社交媒體。

服務器會話失效可以通過以下步驟解決:1.檢查服務器配置,確保會話設置正確。 2.驗證客戶端cookies,確認瀏覽器支持並正確發送。 3.檢查會話存儲服務,如Redis,確保其正常運行。 4.審查應用代碼,確保會話邏輯正確。通過這些步驟,可以有效診斷和修復會話問題,提升用戶體驗。

session_start()iscucialinphpformanagingusersessions.1)ItInitiateSanewsessionifnoneexists,2)resumesanexistingsessions,and3)setsasesessionCookieforContinuityActinuityAccontinuityAcconActInityAcconActInityAcconAccRequests,EnablingApplicationsApplicationsLikeUseAppericationLikeUseAthenticationalticationaltication and PersersonalizedContentent。

設置httponly標誌對會話cookie至關重要,因為它能有效防止XSS攻擊,保護用戶會話信息。具體來說,1)httponly標誌阻止JavaScript訪問cookie,2)在PHP和Flask中可以通過setcookie和make_response設置該標誌,3)儘管不能防範所有攻擊,但應作為整體安全策略的一部分。

phpsessions solvathepromblymaintainingStateAcrossMultipleHttpRequestsbyStoringDataTaNthEserVerAndAssociatingItwithaIniquesestionId.1)他們儲存了AtoredAtaserver side,通常是Infilesordatabases,InseasessessionIdStoreDistordStoredStoredStoredStoredStoredStoredStoreDoreToreTeReTrestaa.2)

tostartaphpsession,usesesses_start()attheScript'Sbeginning.1)placeitbeforeanyOutputtosetThesessionCookie.2)useSessionsforuserDatalikeloginstatusorshoppingcarts.3)regenerateSessiveIdStopreventFentfixationAttacks.s.4)考慮使用AttActAcks.s.s.4)

會話再生是指在用戶進行敏感操作時生成新會話ID並使舊ID失效,以防會話固定攻擊。實現步驟包括:1.檢測敏感操作,2.生成新會話ID,3.銷毀舊會話ID,4.更新用戶端會話信息。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

Dreamweaver CS6
視覺化網頁開發工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

SublimeText3漢化版
中文版,非常好用

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。