Nếu bạn đang tìm cách kiểm tra cấu hình PHP của trang web, còn được gọi là phpinfo, bạn đã đến đúng nơi. Ví dụ: bạn có thể muốn kiểm tra xem cấu hình PHP của mình có đáp ứng yêu cầu của bất kỳ phần mềm nào bạn muốn chạy trên máy chủ của mình không
Trong hướng dẫn này, chúng tôi sẽ chỉ cho bạn cách tạo tệp phpinfo và cả cách kiểm tra thông tin chi tiết của tệp đó bằng các công cụ được cung cấp trong bảng điều khiển lưu trữ của bạn. Vì vậy, hay thực hiện ngay bây giơ
//httpd.apache.org/docs/2.4/mod/core.html#options# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
Mặc định khi bạn cài xampp thì
My First Website
Hello, World!
3 sẽ trỏ về
My First Website
Hello, World!
5, nghĩa là nó sẽ phục vụ các file trong thư mục
My First Website
Hello, World!
6Hãy tiếp tục và tạo một thư mục mới và đặt tên cho nó theo ý muốn của bạn và sửa đổi
My First Website
Hello, World!
3 như vậy
My First Website
Hello, World!
8Bạn luôn có thể thay đổi đường dẫn
My First Website
Hello, World!
3 thành bất cứ đâu bạn muốn. Theo ý kiến của tôi, đây chỉ là một cách sạch hơn nhiều để nhóm các dự án PHP của bạnThời gian để bắt đầu viết mãTrước khi bắt tay vào viết mã, bạn cần có hai thứ
- Nhận và IDE của sự lựa chọn của bạn. [Visual Studio Code, Atom, Eclipse hoặc có lẽ là Notepad++]
- Đảm bảo rằng bạn đã khởi động Apache từ xampp. Nếu bạn đang sử dụng phiên bản 8 mới nhất trở lên, hãy truy cập vào
20 để bắt đầu khởi động máy chủ
My First WebsiteHello, World!
Bây giờ, hãy truy cập vào
My First Website
Hello, World!
21 mà bạn đã tạo trong thư mục
My First Website
Hello, World!
6Tạo một tệp mới và đặt tên là
My First Website
Hello, World!
23. Mở nó lên và dán như sau
My First Website
Hello, World!
Tất nhiên, chúng ta cần bắt đầu với
My First Website
Hello, World!
24 truyền thống cho trang đầu tiên của bạn. Lưu tệp và nhớ khởi động Apache của bạn với xampp. Mở trình duyệt của bạn và truy cập
My First Website
Hello, World!
25. Bạn sẽ thấy truyền thống trong lập trình. Chào thế giớimục lục. php
Vì vậy, bây giờ chúng ta hãy đi xa hơn
Bố cục cơ bản của các trang web
Bất kỳ trang web chung nào thường bao gồm ít nhất 3 phần riêng biệt được gọi là
My First Website
Hello, World!
26 ,
My First Website
Hello, World!
27 và
My First Website
Hello, World!
28Bây giờ bạn có thể đoán rằng
My First Website
Hello, World!
26 là phần của trang nơi nó hiển thị logo của trang web, menu điều hướng, tìm kiếm, hồ sơ người dùng, v.v.
My First Website
Hello, World!
27 là phần dưới cùng của trang web nơi chúng tôi thường hiển thị những thứ linh tinh như liên kết mạng xã hội, menu liên hệ với chúng tôi, quyền riêng tư & chính sách cùng những thứ khácPhần
My First Website
Hello, World!
28 là tốt, bây giờ có lẽ bạn đã biết rằng phần
My First Website
Hello, World!
28 là phần giữa
My First Website
Hello, World!
26 và
My First Website
Hello, World!
27Có những thứ khác mà bạn có thể thấy trên một trang web như thanh bên rất phổ biến đối với các trang quản trị và tiện ích trang web
Tạo một trang có Header, Main và Footer
Mở trang
My First Website
Hello, World!
23 của bạn và dán nội dung sau
My First Website
Hello, World!
2Tải lại trang và bạn sẽ thấy đầu trang và chân trang cơ bản
trang chủ
Bây giờ hãy coi bạn
My First Website
Hello, World!
23 là trang chủ của bạn. Bạn có thể thấy có 3 menu trong thanh điều hướng của mình ở phần trên cùng của trangRất tiếc, hiện chỉ có menu
My First Website
Hello, World!
17 hoạt động, 2 menu còn lại thì khôngĐiều này là do trang cho menu tương ứng chưa tồn tại
Hãy tiếp tục tạo hai trang này
Tạo thêm trang
Trong PHP, một trang web về cơ bản là một tệp
My First Website
Hello, World!
18. Nếu bạn là người mới bắt đầu và nếu điều này làm bạn bối rối, hãy để tôi giải thíchKhi bạn mở trình duyệt của mình và nhập ví dụ:
My First Website
Hello, World!
19 và sau đó bạn nhấn enter, điều xảy ra ở đây là bạn thực sự đang gửi yêu cầu đến máy chủ, máy chủ sẽ đọc, diễn giải yêu cầu và trả lại phản hồi. Trong trường hợp này, máy chủ sẽ phản hồi lại bằng cách gửi tệp
My First Website
Hello, World!
40, tệp này sau đó hiển thị trên trình duyệt của bạn dưới dạng trang web. Khá dễ dàng phải không?Hãy tiếp tục và tạo hai tệp mới,
My First Website
Hello, World!
40 và
My First Website
Hello, World!
42Sao chép mã bên dưới bắt đầu bằng
My First Website
Hello, World!
40 và
My First Website
Hello, World!
42
My First Website
Hello, World!
1
My First Website
Hello, World!
42
My First Website
Hello, World!
4Bây giờ, hãy thử menu điều hướng, nó sẽ hiển thị trang tương ứng khi nhấp vào
Trang động với PHPCho đến nay, tất cả những gì chúng tôi đã làm chỉ là viết một số HTML thực sự cơ bản
Vâng, đây là phần tốt
Lưu ý rằng trong cả ba tệp mà chúng tôi đã tạo cho đến nay, tất cả
My First Website
Hello, World!
46 đều có cùng HTML ngoại trừ
My First Website
Hello, World!
47 hiển thị tên trang tương ứngHãy tưởng tượng nếu chúng ta có nhiều trang và sau đó chúng ta cần thay đổi chẳng hạn như
My First Website
Hello, World!
48 hoặc có thể thêm nhiều hơn nữa
My First Website
Hello, World!
49 hoặc
My First Website
Hello, World!
60 trong phần
My First Website
Hello, World!
61 của trang. Sau đó, bạn sẽ phải đi đến từng trang để thực hiện các thay đổiCó vẻ khá nan giải phải không?
Đây là nơi PHP phát huy tác dụng. Chúng tôi có thể nhóm hoặc tách phần tương tự trong mỗi trang và cô lập nó trong một tệp duy nhất. Sau đó, chúng tôi có thể sử dụng PHP để đưa nó vào bất kỳ trang nào chúng tôi muốn
Tạo hai tệp mới có tên là
My First Website
Hello, World!
62 và
My First Website
Hello, World!
63Mở
My First Website
Hello, World!
62 và dán như sau
My First Website
Hello, World!
6Sau đó, mở
My First Website
Hello, World!
63 và dán thông tin sauDocumentRoot "C:/xampp/htdocs"3
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
Hiện tại,
My First Website
Hello, World!
23 của bạn chỉ nên chứa nội dung nàyDocumentRoot "C:/xampp/htdocs"5
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
Nếu bạn vào trang chủ của mình, bạn sẽ chỉ thấy dòng chữ
My First Website
Hello, World!
67. Thanh điều hướng và chân trang hiện đã biến mấtQuay lại
My First Website
Hello, World!
23 và dán thông tin sauDocumentRoot "C:/xampp/htdocs"8
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
Paste ở trên vào 2 file còn lại và nhớ thay _
My First Website
Hello, World!
47Đoạn mã trên chứa hàm PHP là
DocumentRoot "C:/xampp/htdocs"30 thực sự lấy tệp mà bạn chỉ định. Mọi nội dung của tệp mà bạn
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
DocumentRoot "C:/xampp/htdocs"31 sau đó sẽ có sẵn trong tệp mà bạn gọi hàm
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
Khá gọn gàng phải không?
Được rồi, tiếp tục. Hãy xem chúng ta có thể làm gì khác với PHP trong phát triển web
Cơ sở dữ liệu trong phát triển webHầu hết mọi trang web trên internet đều có một loại cơ sở dữ liệu mà nó phụ thuộc vào để lưu dữ liệu
Ví dụ: khi bạn đăng nhập vào một trang web, nó sẽ lưu dữ liệu tên người dùng và mật khẩu đăng nhập của bạn
Một ví dụ khác như khi bạn đang duyệt qua một trang web thương mại điện tử và tìm thấy một sản phẩm bạn thích, khi nhấp vào nút, nó sẽ lưu sản phẩm đó vào giỏ hàng của bạn, điều này cũng liên quan đến việc lưu sản phẩm đó vào cơ sở dữ liệu. Vì vậy, lần sau khi bạn mở trang web, bạn vẫn có thể xem sản phẩm trong giỏ hàng của mình
Với ý nghĩ đó, hãy xem cách chúng ta có thể sử dụng PHP để kết nối với cơ sở dữ liệu
Trước khi làm điều đó, trước tiên hãy tạo cơ sở dữ liệu của chúng tôi trong MySQL
Khi bạn cài đặt XAMPP, nó cũng đi kèm với MySQL, điều này thực sự tuyệt vời
Chuyển đến
DocumentRoot "C:/xampp/htdocs"32 và nhấp vào nút
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
DocumentRoot "C:/xampp/htdocs"33 ở phía bên trái của trang
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
phpmyadmin
Nhập tên cơ sở dữ liệu mà bạn muốn tạo và nhấp vào
DocumentRoot "C:/xampp/htdocs"34
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
tạo db
Hãy nhớ tên cơ sở dữ liệu của bạn vì chúng tôi sẽ cần đến nó sau này
Khi tạo thành công, nhấp vào cơ sở dữ liệu mà bạn vừa tạo
tạo bảng
Tạo một bảng
DocumentRoot "C:/xampp/htdocs"35. Nhấp vào nút
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
DocumentRoot "C:/xampp/htdocs"36
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
bảng người dùng
Chỉ cần làm theo cấu hình trên để tạo bảng
DocumentRoot "C:/xampp/htdocs"35. Nhấp vào
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
DocumentRoot "C:/xampp/htdocs"38
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
Bạn sẽ thấy một cái gì đó như thế này sau khi tạo bảng thành công
Bây giờ việc cần làm là tạo một vài bảng dữ liệu hoặc bản ghi
Nhấp vào
DocumentRoot "C:/xampp/htdocs"39 ở phần trên cùng bên cạnh
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
DocumentRoot "C:/xampp/htdocs"50
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# //httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks Includes ExecCGI#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride All#
# Controls who can get stuff from this server.
#
Require all granted
chèn dữ liệu
Bạn có thể tạo bao nhiêu bản ghi tùy thích nếu muốn. Bây giờ chúng ta đã hoàn thành với cơ sở dữ liệu
Kết nối cơ sở dữ liệu với PHP
Quay trở lại
My First Website
Hello, World!
23 của bạn và dán thông tin sau
My First Website
Hello, World!
2Nhớ thay thế tên cơ sở dữ liệu trong mã
Làm mới trang và bạn sẽ có một cái gì đó như thế này
trang chủThe End…
Trên đây chỉ là những thứ cơ bản trong phát triển web với PHP và nếu bạn chưa quen với điều này, tôi thực sự khuyên bạn nên dành thời gian để hiểu tất cả những điều trên, đặc biệt là phần động và phần cơ sở dữ liệu
Chỉ là một mẹo nhỏ, nếu bạn là người mới, sau phần này, tôi khuyên bạn nên xem xét CRUD với PHP. Nếu bạn đang tìm kiếm một thử thách, thì có lẽ bạn có thể thử tạo một hệ thống đăng nhập bằng PHP. Hãy xem tại đây, Đăng nhập bằng PHP với MySQL