php5 的 session_start() 注意事項

我們經常利用$_SESSION 的變數,來傳遞認證是否有通過的key,
PHP5.4 為了使用$_SESSION[],必須要先在檔案開始宣告 session_start(),但session_start()放置的位置要注意,不可以放置在 <html></html>之前,若要隱蔽網頁內容需認證才能看到,可以放在<body></body>前就好。否則容易在 Apache 2.4 出現如
.htaccess設定 鎖住特定資料夾如 myfolder
<Directory myfolder>
AllowOverride AuthConfig
Order Allow,Deny 
Allow from 140.*.*.*
</Directory>

的情形,變成該網頁讀取,會不斷詢問apache htaccess 帳號密碼。

這個網誌中的熱門文章

Upgrade php and httpd(apache) on CentOS 7

Installing VMware workstation pro on Ubuntu 22.X (Jammy Jellyfish)