Fix lỗi undefined index $_SERVER['HTTPS'] và port $_SERVER['SERVER_PORT'] luôn trả ra 80 khi truy cập vào https

Khi lập trình php cần thao tác trên host https. Các bạn có thể gặp trường hợp  undefined index $_SERVER['HTTPS'] và port $_SERVER['SERVER_PORT'] luôn trả ra 80 khi truy cập vào https. Có thể tạm fix như sau:

1. Các bạn chỉ cần sửa vhost cấu hình apache như thế này:

<VirtualHost *:80>
   DocumentRoot D:\xampp\htdocs\abc
   ServerName abc.vn.vn
</VirtualHost>
<VirtualHost *:443>   
   setEnv HTTPS on   
   DocumentRoot D:\xampp\htdocs\abc
   ServerName abc.vn:443   
   UseCanonicalName On
</VirtualHost>

2. Restart apache
3. Dump xem kết quả
var_dump($_SERVER); die;

Bài đăng phổ biến từ blog này

Đệ quy trong MIPS