Hướng dẫn dùng pop one trong PHP
Định nghĩa và cách dùng include và require
include
Cấu trúcđường_dẫn_file/tên_file"; ?> Ví dụ:
Content
Ta thấy nội dung 2 file header.php và footer.php đã được thêm vào. Download file ví dụ include với file không tồn tại// Giả sử file header.php không có Content
Warning: include(header.php): failed to open stream: No such file or directory in C:\xampp\htdocs\example\index.php on line 1 Warning: include(): Failed opening 'header.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\example\index.php on line 1 Content Ta thấy trình duyệt gửi cảnh báo, tuy nhiên những PHP vẫn thực thi những đoạn code bên dưới. require
Cấu trúcđường_dẫn_file/tên_file"; ?> Ví dụ:
Content
Nội dung 2 file header.php và footer.php đã được thêm vào. Download file ví dụ require với file không tồn tại// Giả sử file header.php không có Content
Warning: require(header.php): failed to open stream: No such file or directory in C:\xampp\htdocs\example\index.php on line 1 Fatal error: require(): Failed opening required 'header.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\example\index.php on line 1 Ta thấy trình duyệt gửi cảnh báo, và những đoạn code bên dưới đã không được thực thi. PHP include và require với pathLưu ý: nếu chưa được cấu hình đường dẫn tương đối (relative path) thì dễ xảy ra lỗi khi dùng Sử dụng đường dẫn tuyệt đốiSử dụng cách này cần kích hoạt allow_url_fopen và allow_url_include sang On trong php.ini
Content
Download file ví dụ Sử dụng DOCUMENT_ROOT
Content
Download file ví dụ |