Hướng dẫn how do i find the hostname of a php server? - làm cách nào để tìm tên máy chủ của máy chủ php?

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

gethostnameGets the host name

Description

gethostname(): string|false

Parameters

This function has no parameters.

Return Values

Returns a string with the hostname on success, otherwise false is returned.

Examples

Example #1 A simple gethostname() example

echo gethostname(); // may output e.g,: sandie
?>

See Also

  • gethostbyname() - Get the IPv4 address corresponding to a given Internet host name
  • gethostbyaddr() - Get the Internet host name corresponding to a given IP address
  • php_uname() - Returns information about the operating system PHP is running on

markosjal AT Gmail

6 months ago

Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local"

solaris

2 years ago

To the prev. note: **NEVER USE***
#`sudo hostname servername`

Some *nix systems will then force to set the 'servername' as new hostname!

kurdtpage at gmail dot com

4 years ago

On Linux, use the command `hostname` to view your host name, or `sudo hostname servername` to set it

Mark Simon ¶

Richard York ¶Server and execution environment information

Stefano (Thông tin tại Sarchittu Dot Org) ¶

Danieltahar ¶

Chỉ số

Bạn có thể hoặc không thể tìm thấy bất kỳ yếu tố nào sau đây trong $ _Server. Lưu ý rằng rất ít, nếu có, trong số này sẽ có sẵn (hoặc thực sự có bất kỳ ý nghĩa nào) nếu chạy PHP trên dòng lệnh.

'Php_elf' Tên tệp của tập lệnh hiện đang thực hiện, liên quan đến gốc tài liệu. Chẳng hạn, $ _Server ['php_elf'] trong một tập lệnh tại địa chỉ http://example.com/foo/bar.php sẽ là /foo/bar.php. Hằng số __file__ chứa đường dẫn và tên tệp đầy đủ của tệp hiện tại (tức là bao gồm). Nếu PHP đang chạy như một bộ xử lý dòng lệnh này, biến này chứa tên tập lệnh. 'Argv' mảng các đối số được truyền cho tập lệnh. Khi tập lệnh được chạy trên dòng lệnh, điều này cho phép truy cập kiểu C vào các tham số dòng lệnh. Khi được gọi qua phương thức GET, điều này sẽ chứa chuỗi truy vấn. 'ARGC' chứa số lượng tham số dòng lệnh được truyền vào tập lệnh (nếu chạy trên dòng lệnh). 'Gateway_interface' Bản sửa đổi của đặc tả CGI mà máy chủ đang sử dụng; ví dụ. 'CGI/1.1'. 'Server_addr' địa chỉ IP của máy chủ theo đó tập lệnh hiện tại đang thực hiện. 'Server_name' Tên của máy chủ máy chủ theo đó tập lệnh hiện tại đang thực thi. Nếu tập lệnh đang chạy trên máy chủ ảo, đây sẽ là giá trị được xác định cho máy chủ ảo đó. The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/foo/bar.php would be /foo/bar.php. The __FILE__ constant contains the full path and filename of the current (i.e. included) file. If PHP is running as a command-line processor this variable contains the script name. 'argv' Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string. 'argc' Contains the number of command line parameters passed to the script (if run on the command line). 'GATEWAY_INTERFACE' What revision of the CGI specification the server is using; e.g. 'CGI/1.1'. 'SERVER_ADDR' The IP address of the server under which the current script is executing. 'SERVER_NAME' The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.

Lưu ý: Theo Apache 2, bạn phải đặt UseCanonicalName = OnServerName. Mặt khác, giá trị này phản ánh tên máy chủ do khách hàng cung cấp, có thể bị giả mạo. Không an toàn khi dựa vào giá trị này trong bối cảnh phụ thuộc bảo mật.: Under Apache 2, you must set UseCanonicalName = On and ServerName. Otherwise, this value reflects the hostname supplied by the client, which can be spoofed. It is not safe to rely on this value in security-dependent contexts.

Chuỗi nhận dạng máy chủ 'server_software', được đưa ra trong các tiêu đề khi trả lời các yêu cầu. Tên 'server_protocol' và sửa đổi giao thức thông tin thông qua đó trang được yêu cầu; ví dụ. ' echo gethostname(); // may output e.g,: sandie
?>
0'; 'Request_method' phương thức yêu cầu nào được sử dụng để truy cập trang; ví dụ. ' echo gethostname(); // may output e.g,: sandie
?>
1', ' echo gethostname(); // may output e.g,: sandie
?>
2', ' echo gethostname(); // may output e.g,: sandie
?>
3', ' echo gethostname(); // may output e.g,: sandie
?>
4'. Server identification string, given in the headers when responding to requests. 'SERVER_PROTOCOL' Name and revision of the information protocol via which the page was requested; e.g. ' echo gethostname(); // may output e.g,: sandie
?>
0';
'REQUEST_METHOD' Which request method was used to access the page; e.g. ' echo gethostname(); // may output e.g,: sandie
?>
1', ' echo gethostname(); // may output e.g,: sandie
?>
2', ' echo gethostname(); // may output e.g,: sandie
?>
3', ' echo gethostname(); // may output e.g,: sandie
?>
4'.

Ghi chú::

Tập lệnh PHP bị chấm dứt sau khi gửi các tiêu đề (điều đó có nghĩa là sau khi tạo bất kỳ đầu ra nào mà không có bộ đệm đầu ra) nếu phương thức yêu cầu là echo gethostname(); // may output e.g,: sandie
?>
2.

'Request_time' dấu thời gian bắt đầu yêu cầu. 'Request_time_float' dấu thời gian bắt đầu yêu cầu, với độ chính xác microsecond. 'Query_String' chuỗi truy vấn, nếu có, thông qua đó trang được truy cập. 'Document_root' thư mục gốc tài liệu theo đó tập lệnh hiện tại đang thực thi, như được định nghĩa trong tệp cấu hình của máy chủ. 'Http_accept' nội dung của tiêu đề echo gethostname(); // may output e.g,: sandie
?>
6 từ yêu cầu hiện tại, nếu có. 'Http_accept_charset' nội dung của tiêu đề echo gethostname(); // may output e.g,: sandie
?>
7 từ yêu cầu hiện tại, nếu có. Ví dụ: ' echo gethostname(); // may output e.g,: sandie
?>
8'. 'Http_accept_encoding' nội dung của tiêu đề echo gethostname(); // may output e.g,: sandie
?>
9 từ yêu cầu hiện tại, nếu có. Ví dụ: ' Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 0'. 'Http_accept_langage' nội dung của tiêu đề Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 1 từ yêu cầu hiện tại, nếu có. Ví dụ: ' Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 2'. 'HTTP_Connection' nội dung của tiêu đề Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 3 từ yêu cầu hiện tại, nếu có. Ví dụ: ' Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 4'. 'Http_host' nội dung của tiêu đề Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 5 từ yêu cầu hiện tại, nếu có. 'Http_referer' địa chỉ của trang (nếu có) giới thiệu tác nhân người dùng đến trang hiện tại. Điều này được đặt bởi tác nhân người dùng. Không phải tất cả các đại lý người dùng sẽ đặt điều này và một số cung cấp khả năng sửa đổi http_referer làm tính năng. Nói tóm lại, nó không thể thực sự được tin tưởng. 'Http_user_agent' nội dung của tiêu đề Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 6 từ yêu cầu hiện tại, nếu có. Đây là một chuỗi biểu thị tác nhân người dùng đang truy cập trang. Một ví dụ điển hình là: mozilla/4.5 [en] (x11; u; linux 2.2.9 i586). Trong số những thứ khác, bạn có thể sử dụng giá trị này với get_browser () để điều chỉnh đầu ra của trang của bạn theo khả năng của tác nhân người dùng. 'HTTPS' được đặt thành giá trị không trống nếu tập lệnh được truy vấn thông qua giao thức HTTPS. 'Remote_addr' địa chỉ IP mà người dùng đang xem trang hiện tại. 'Remote_host' Tên máy chủ mà người dùng đang xem trang hiện tại. Tra cứu DNS ngược dựa trên Remote_addr của người dùng. The timestamp of the start of the request. 'REQUEST_TIME_FLOAT' The timestamp of the start of the request, with microsecond precision. 'QUERY_STRING' The query string, if any, via which the page was accessed. 'DOCUMENT_ROOT' The document root directory under which the current script is executing, as defined in the server's configuration file. 'HTTP_ACCEPT' Contents of the echo gethostname(); // may output e.g,: sandie
?>
6 header from the current request, if there is one.
'HTTP_ACCEPT_CHARSET' Contents of the echo gethostname(); // may output e.g,: sandie
?>
7 header from the current request, if there is one. Example: ' echo gethostname(); // may output e.g,: sandie
?>
8'.
'HTTP_ACCEPT_ENCODING' Contents of the echo gethostname(); // may output e.g,: sandie
?>
9 header from the current request, if there is one. Example: ' Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 0'.
'HTTP_ACCEPT_LANGUAGE' Contents of the Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 1 header from the current request, if there is one. Example: ' Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 2'. 'HTTP_CONNECTION' Contents of the Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 3 header from the current request, if there is one. Example: ' Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 4'. 'HTTP_HOST' Contents of the Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 5 header from the current request, if there is one. 'HTTP_REFERER' The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted. 'HTTP_USER_AGENT' Contents of the Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 6 header from the current request, if there is one. This is a string denoting the user agent being which is accessing the page. A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586). Among other things, you can use this value with get_browser() to tailor your page's output to the capabilities of the user agent. 'HTTPS' Set to a non-empty value if the script was queried through the HTTPS protocol. 'REMOTE_ADDR' The IP address from which the user is viewing the current page. 'REMOTE_HOST' The Host name from which the user is viewing the current page. The reverse dns lookup is based on the REMOTE_ADDR of the user.

Lưu ý: Máy chủ web của bạn phải được cấu hình để tạo biến này. Ví dụ: trong Apache, bạn sẽ cần Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 7 bên trong httpd.conf để nó tồn tại. Xem thêm Gethostbyaddr ().: Your web server must be configured to create this variable. For example in Apache you'll need Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 7 inside httpd.conf for it to exist. See also gethostbyaddr().

'Remote_port' cổng đang được sử dụng trên máy của người dùng để liên lạc với máy chủ web. 'Remote_user' người dùng được xác thực. 'Redirect_Remote_user' Người dùng được xác thực nếu yêu cầu được chuyển hướng nội bộ. 'Script_filename' The port being used on the user's machine to communicate with the web server. 'REMOTE_USER' The authenticated user. 'REDIRECT_REMOTE_USER' The authenticated user if the request is internally redirected. 'SCRIPT_FILENAME'

Tên đường dẫn tuyệt đối của tập lệnh hiện đang thực thi.

Ghi chú::

Nếu một tập lệnh được thực thi với CLI, dưới dạng đường dẫn tương đối, chẳng hạn như file.php hoặc ../file.php, $ _server ['script_filename'] sẽ chứa đường dẫn tương đối được chỉ định bởi người dùng.

'Server_admin' Giá trị được cung cấp cho lệnh server_admin (cho apache) trong tệp cấu hình máy chủ web. Nếu tập lệnh đang chạy trên máy chủ ảo, đây sẽ là giá trị được xác định cho máy chủ ảo đó. 'Server_port' cổng trên máy chủ đang được máy chủ web sử dụng để liên lạc. Đối với các thiết lập mặc định, đây sẽ là ' Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 8'; Ví dụ, sử dụng SSL sẽ thay đổi điều này thành bất cứ điều gì mà cổng HTTP an toàn đã xác định của bạn. The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file. If the script is running on a virtual host, this will be the value defined for that virtual host. 'SERVER_PORT' The port on the server machine being used by the web server for communication. For default setups, this will be ' Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 8'; using SSL, for instance, will change this to whatever your defined secure HTTP port is.

Lưu ý: Theo Apache 2, bạn phải đặt UseCanonicalName = On, cũng như To the prev. note: **NEVER USE***
#`sudo hostname servername`
0 để có được cổng vật lý (thực), nếu không, giá trị này có thể bị giả mạo và nó có thể hoặc không thể trả về giá trị cổng vật lý. Không an toàn khi dựa vào giá trị này trong bối cảnh phụ thuộc bảo mật.
: Under the Apache 2, you must set UseCanonicalName = On, as well as To the prev. note: **NEVER USE***
#`sudo hostname servername`
0 in order to get the physical (real) port, otherwise, this value can be spoofed and it may or may not return the physical port value. It is not safe to rely on this value in security-dependent contexts.

Chuỗi 'server_signature' chứa phiên bản máy chủ và tên máy chủ ảo được thêm vào các trang do máy chủ tạo, nếu được bật. Hệ thống tập tin 'path_translated' (không phải là đường dẫn dựa trên root-) dựa trên tập lệnh hiện tại, sau khi máy chủ đã thực hiện bất kỳ ánh xạ ảo đến thực tế nào. String containing the server version and virtual host name which are added to server-generated pages, if enabled. 'PATH_TRANSLATED' Filesystem- (not document root-) based path to the current script, after the server has done any virtual-to-real mapping.

Lưu ý: Người dùng Apache 2 có thể sử dụng To the prev. note: **NEVER USE***
#`sudo hostname servername`
1 bên trong httpd.conf để xác định path_info.
: Apache 2 users may use To the prev. note: **NEVER USE***
#`sudo hostname servername`
1 inside httpd.conf to define PATH_INFO.

'Script_name' chứa đường dẫn của tập lệnh hiện tại. Điều này rất hữu ích cho các trang cần phải chỉ vào chính mình. Hằng số __file__ chứa đường dẫn và tên tệp đầy đủ của tệp hiện tại (tức là bao gồm). 'Request_uri' URI được đưa ra để truy cập trang này; Ví dụ, ' To the prev. note: **NEVER USE***
#`sudo hostname servername`
2'. 'PHP_AUTH_DIGEST' Khi thực hiện xác thực HTTP Digest HTTP này được đặt thành tiêu đề 'ủy quyền' được gửi bởi máy khách (sau đó bạn nên sử dụng để thực hiện xác thực phù hợp). 'PHP_AUTH_USER' Khi thực hiện xác thực HTTP, biến này được đặt thành tên người dùng do người dùng cung cấp. 'PHP_AUTH_PW' Khi thực hiện xác thực HTTP, biến này được đặt thành mật khẩu do người dùng cung cấp. 'Auth_Type' Khi thực hiện xác thực HTTP Biến này được đặt thành loại xác thực. 'PATH_INFO' chứa bất kỳ thông tin đường dẫn do khách hàng cung cấp theo tên tệp tập lệnh thực tế nhưng trước chuỗi truy vấn, nếu có. Chẳng hạn, nếu tập lệnh hiện tại được truy cập thông qua URL http://www.example.com/php/path_info.php/some/stuff?foo=bar, thì $ _server ['path_info'] sẽ chứa To the prev. note: **NEVER USE***
#`sudo hostname servername`
3. 'Orig_path_info' phiên bản gốc của 'path_info' trước khi được xử lý bởi PHP. Contains the current script's path. This is useful for pages which need to point to themselves. The __FILE__ constant contains the full path and filename of the current (i.e. included) file. 'REQUEST_URI' The URI which was given in order to access this page; for instance, ' To the prev. note: **NEVER USE***
#`sudo hostname servername`
2'.
'PHP_AUTH_DIGEST' When doing Digest HTTP authentication this variable is set to the 'Authorization' header sent by the client (which you should then use to make the appropriate validation). 'PHP_AUTH_USER' When doing HTTP authentication this variable is set to the username provided by the user. 'PHP_AUTH_PW' When doing HTTP authentication this variable is set to the password provided by the user. 'AUTH_TYPE' When doing HTTP authentication this variable is set to the authentication type. 'PATH_INFO' Contains any client-provided pathname information trailing the actual script filename but preceding the query string, if available. For instance, if the current script was accessed via the URL http://www.example.com/php/path_info.php/some/stuff?foo=bar, then $_SERVER['PATH_INFO'] would contain To the prev. note: **NEVER USE***
#`sudo hostname servername`
3.
'ORIG_PATH_INFO' Original version of 'PATH_INFO' before processed by PHP.

Ví dụ

Ví dụ #1 $ _Server Ví dụ

To the prev. note: **NEVER USE***
#`sudo hostname servername`
4

Ví dụ trên sẽ xuất ra một cái gì đó tương tự như:

Ghi chú

Ghi chú::

Nếu một tập lệnh được thực thi với CLI, dưới dạng đường dẫn tương đối, chẳng hạn như file.php hoặc ../file.php, $ _server ['script_filename'] sẽ chứa đường dẫn tương đối được chỉ định bởi người dùng.global $variable; to access it within functions or methods.

'Server_admin' Giá trị được cung cấp cho lệnh server_admin (cho apache) trong tệp cấu hình máy chủ web. Nếu tập lệnh đang chạy trên máy chủ ảo, đây sẽ là giá trị được xác định cho máy chủ ảo đó. 'Server_port' cổng trên máy chủ đang được máy chủ web sử dụng để liên lạc. Đối với các thiết lập mặc định, đây sẽ là ' Since I built a PHP app that runs on Linux Windows and MacOS I just discovered that using gethostname() behaves differently on different OSes. Linux will return "hostname" while MacOS 10.15 will return "hostname.local"  . Have yet to determine how Windows behaves but the difference is worth noting. Only a few days ago I was wanting to get the LAN extension in Linux and was never able to. I was oly hable to get "hostname".  In MacOS it is just there. with "hostname.local" 8'; Ví dụ, sử dụng SSL sẽ thay đổi điều này thành bất cứ điều gì mà cổng HTTP an toàn đã xác định của bạn.

Lưu ý: Theo Apache 2, bạn phải đặt UseCanonicalName = On, cũng như To the prev. note: **NEVER USE***
#`sudo hostname servername`
0 để có được cổng vật lý (thực), nếu không, giá trị này có thể bị giả mạo và nó có thể hoặc không thể trả về giá trị cổng vật lý. Không an toàn khi dựa vào giá trị này trong bối cảnh phụ thuộc bảo mật.

To the prev. note: **NEVER USE***
#`sudo hostname servername`
5

To the prev. note: **NEVER USE***
#`sudo hostname servername`
6

To the prev. note: **NEVER USE***
#`sudo hostname servername`
7

To the prev. note: **NEVER USE***
#`sudo hostname servername`
8

To the prev. note: **NEVER USE***
#`sudo hostname servername`
9

Some *nix systems will then force to set the 'servername' as new hostname!0

Chuỗi 'server_signature' chứa phiên bản máy chủ và tên máy chủ ảo được thêm vào các trang do máy chủ tạo, nếu được bật. Hệ thống tập tin 'path_translated' (không phải là đường dẫn dựa trên root-) dựa trên tập lệnh hiện tại, sau khi máy chủ đã thực hiện bất kỳ ánh xạ ảo đến thực tế nào.

Lưu ý: Người dùng Apache 2 có thể sử dụng To the prev. note: **NEVER USE***
#`sudo hostname servername`
1 bên trong httpd.conf để xác định path_info.

Some *nix systems will then force to set the 'servername' as new hostname!2

Some *nix systems will then force to set the 'servername' as new hostname!3

Some *nix systems will then force to set the 'servername' as new hostname!4

'Script_name' chứa đường dẫn của tập lệnh hiện tại. Điều này rất hữu ích cho các trang cần phải chỉ vào chính mình. Hằng số __file__ chứa đường dẫn và tên tệp đầy đủ của tệp hiện tại (tức là bao gồm). 'Request_uri' URI được đưa ra để truy cập trang này; Ví dụ, ' To the prev. note: **NEVER USE***
#`sudo hostname servername`
2'. 'PHP_AUTH_DIGEST' Khi thực hiện xác thực HTTP Digest HTTP này được đặt thành tiêu đề 'ủy quyền' được gửi bởi máy khách (sau đó bạn nên sử dụng để thực hiện xác thực phù hợp). 'PHP_AUTH_USER' Khi thực hiện xác thực HTTP, biến này được đặt thành tên người dùng do người dùng cung cấp. 'PHP_AUTH_PW' Khi thực hiện xác thực HTTP, biến này được đặt thành mật khẩu do người dùng cung cấp. 'Auth_Type' Khi thực hiện xác thực HTTP Biến này được đặt thành loại xác thực. 'PATH_INFO' chứa bất kỳ thông tin đường dẫn do khách hàng cung cấp theo tên tệp tập lệnh thực tế nhưng trước chuỗi truy vấn, nếu có. Chẳng hạn, nếu tập lệnh hiện tại được truy cập thông qua URL http://www.example.com/php/path_info.php/some/stuff?foo=bar, thì $ _server ['path_info'] sẽ chứa To the prev. note: **NEVER USE***
#`sudo hostname servername`
3. 'Orig_path_info' phiên bản gốc của 'path_info' trước khi được xử lý bởi PHP.

Ví dụ

Some *nix systems will then force to set the 'servername' as new hostname!6

Some *nix systems will then force to set the 'servername' as new hostname!7

Some *nix systems will then force to set the 'servername' as new hostname!8

Some *nix systems will then force to set the 'servername' as new hostname!9

0

1

2

3

4

5

6

7

Ví dụ #1 $ _Server Ví dụ

Lưu ý: Theo Apache 2, bạn phải đặt UseCanonicalName = On, cũng như To the prev. note: **NEVER USE***
#`sudo hostname servername`
0 để có được cổng vật lý (thực), nếu không, giá trị này có thể bị giả mạo và nó có thể hoặc không thể trả về giá trị cổng vật lý. Không an toàn khi dựa vào giá trị này trong bối cảnh phụ thuộc bảo mật.

9

On Linux, use the command `hostname` to view your host name, or `sudo hostname servername` to set it 0

Chuỗi 'server_signature' chứa phiên bản máy chủ và tên máy chủ ảo được thêm vào các trang do máy chủ tạo, nếu được bật. Hệ thống tập tin 'path_translated' (không phải là đường dẫn dựa trên root-) dựa trên tập lệnh hiện tại, sau khi máy chủ đã thực hiện bất kỳ ánh xạ ảo đến thực tế nào.

Lưu ý: Người dùng Apache 2 có thể sử dụng To the prev. note: **NEVER USE***
#`sudo hostname servername`
1 bên trong httpd.conf để xác định path_info.

On Linux, use the command `hostname` to view your host name, or `sudo hostname servername` to set it 2

On Linux, use the command `hostname` to view your host name, or `sudo hostname servername` to set it 3

'Script_name' chứa đường dẫn của tập lệnh hiện tại. Điều này rất hữu ích cho các trang cần phải chỉ vào chính mình. Hằng số __file__ chứa đường dẫn và tên tệp đầy đủ của tệp hiện tại (tức là bao gồm). 'Request_uri' URI được đưa ra để truy cập trang này; Ví dụ, ' To the prev. note: **NEVER USE***
#`sudo hostname servername`
2'. 'PHP_AUTH_DIGEST' Khi thực hiện xác thực HTTP Digest HTTP này được đặt thành tiêu đề 'ủy quyền' được gửi bởi máy khách (sau đó bạn nên sử dụng để thực hiện xác thực phù hợp). 'PHP_AUTH_USER' Khi thực hiện xác thực HTTP, biến này được đặt thành tên người dùng do người dùng cung cấp. 'PHP_AUTH_PW' Khi thực hiện xác thực HTTP, biến này được đặt thành mật khẩu do người dùng cung cấp. 'Auth_Type' Khi thực hiện xác thực HTTP Biến này được đặt thành loại xác thực. 'PATH_INFO' chứa bất kỳ thông tin đường dẫn do khách hàng cung cấp theo tên tệp tập lệnh thực tế nhưng trước chuỗi truy vấn, nếu có. Chẳng hạn, nếu tập lệnh hiện tại được truy cập thông qua URL http://www.example.com/php/path_info.php/some/stuff?foo=bar, thì $ _server ['path_info'] sẽ chứa To the prev. note: **NEVER USE***
#`sudo hostname servername`
3. 'Orig_path_info' phiên bản gốc của 'path_info' trước khi được xử lý bởi PHP.

Ví dụ

On Linux, use the command `hostname` to view your host name, or `sudo hostname servername` to set it 5

On Linux, use the command `hostname` to view your host name, or `sudo hostname servername` to set it 6

On Linux, use the command `hostname` to view your host name, or `sudo hostname servername` to set it 7

On Linux, use the command `hostname` to view your host name, or `sudo hostname servername` to set it 8

On Linux, use the command `hostname` to view your host name, or `sudo hostname servername` to set it 9

Ví dụ #1 $ _Server Ví dụ

Ví dụ

CGI/1.11

CGI/1.12

CGI/1.13

CGI/1.14

CGI/1.15

CGI/1.16

CGI/1.17

CGI/1.18

Ví dụ #1 $ _Server Ví dụ

Lưu ý: Theo Apache 2, bạn phải đặt UseCanonicalName = On, cũng như To the prev. note: **NEVER USE***
#`sudo hostname servername`
0 để có được cổng vật lý (thực), nếu không, giá trị này có thể bị giả mạo và nó có thể hoặc không thể trả về giá trị cổng vật lý. Không an toàn khi dựa vào giá trị này trong bối cảnh phụ thuộc bảo mật.

UseCanonicalName = On0

UseCanonicalName = On1

UseCanonicalName = On2

UseCanonicalName = On3

UseCanonicalName = On4

Ví dụ #1 $ _Server Ví dụ

Ví dụ

UseCanonicalName = On6

UseCanonicalName = On7

UseCanonicalName = On8

UseCanonicalName = On9

ServerName0

ServerName1

CGI/1.17

Ví dụ #1 $ _Server Ví dụ

Ví dụ trên sẽ xuất ra một cái gì đó tương tự như:

ServerName4

ServerName5

ServerName6

Ghi chú

Đây là một 'Superglobal', hoặc biến toàn cầu, tự động. Điều này đơn giản có nghĩa là nó có sẵn trong tất cả các phạm vi trong suốt một kịch bản. Không cần phải thực hiện biến $ toàn cầu; để truy cập nó trong các chức năng hoặc phương pháp.

ServerName8

ServerName9

Vladimir Kornea ¶

13 năm trước

echo gethostname(); // may output e.g,: sandie
?>
01

Vcoletti tại Tiscali Dot it ¶

Ví dụ

echo gethostname(); // may output e.g,: sandie
?>
02

echo gethostname(); // may output e.g,: sandie
?>
03

echo gethostname(); // may output e.g,: sandie
?>
04

echo gethostname(); // may output e.g,: sandie
?>
05

echo gethostname(); // may output e.g,: sandie
?>
06

echo gethostname(); // may output e.g,: sandie
?>
07

echo gethostname(); // may output e.g,: sandie
?>
08

echo gethostname(); // may output e.g,: sandie
?>
09

echo gethostname(); // may output e.g,: sandie
?>
10

echo gethostname(); // may output e.g,: sandie
?>
11

Steve tại Sc-Fa Dot Com ¶

13 năm trước

echo gethostname(); // may output e.g,: sandie
?>
13

echo gethostname(); // may output e.g,: sandie
?>
14

echo gethostname(); // may output e.g,: sandie
?>
15

Mark Simon ¶

3 năm trước

echo gethostname(); // may output e.g,: sandie
?>
17

echo gethostname(); // may output e.g,: sandie
?>
18

echo gethostname(); // may output e.g,: sandie
?>
19

echo gethostname(); // may output e.g,: sandie
?>
20

echo gethostname(); // may output e.g,: sandie
?>
21

Richard York ¶

13 năm trước

echo gethostname(); // may output e.g,: sandie
?>
23

echo gethostname(); // may output e.g,: sandie
?>
24

Mark Simon ¶

3 năm trước

echo gethostname(); // may output e.g,: sandie
?>
26

echo gethostname(); // may output e.g,: sandie
?>
27

echo gethostname(); // may output e.g,: sandie
?>
28

Richard York ¶

Stefano (Thông tin tại Sarchittu Dot Org) ¶

echo gethostname(); // may output e.g,: sandie
?>
30

echo gethostname(); // may output e.g,: sandie
?>
31

11 năm trước

Danieltahar ¶

echo gethostname(); // may output e.g,: sandie
?>
33

echo gethostname(); // may output e.g,: sandie
?>
34

echo gethostname(); // may output e.g,: sandie
?>
35

echo gethostname(); // may output e.g,: sandie
?>
36

2 năm trước

Chris at Ocproducts Dot Com ¶

echo gethostname(); // may output e.g,: sandie
?>
38

5 năm trước

3 năm trước

echo gethostname(); // may output e.g,: sandie
?>
39

echo gethostname(); // may output e.g,: sandie
?>
40

Richard York ¶

13 năm trước

echo gethostname(); // may output e.g,: sandie
?>
42

Stefano (Thông tin tại Sarchittu Dot Org) ¶

13 năm trước

echo gethostname(); // may output e.g,: sandie
?>
43

echo gethostname(); // may output e.g,: sandie
?>
44

11 năm trước

Danieltahar ¶

echo gethostname(); // may output e.g,: sandie
?>
46

echo gethostname(); // may output e.g,: sandie
?>
47

echo gethostname(); // may output e.g,: sandie
?>
48

echo gethostname(); // may output e.g,: sandie
?>
49

2 năm trước

Danieltahar ¶

echo gethostname(); // may output e.g,: sandie
?>
51

echo gethostname(); // may output e.g,: sandie
?>
52

echo gethostname(); // may output e.g,: sandie
?>
53

echo gethostname(); // may output e.g,: sandie
?>
54

2 năm trước

13 năm trước

echo gethostname(); // may output e.g,: sandie
?>
56

echo gethostname(); // may output e.g,: sandie
?>
57

Chris at Ocproducts Dot Com ¶

5 năm trước

echo gethostname(); // may output e.g,: sandie
?>
59

echo gethostname(); // may output e.g,: sandie
?>
60

Tom ¶

3 năm trước

echo gethostname(); // may output e.g,: sandie
?>
62

echo gethostname(); // may output e.g,: sandie
?>
63

echo gethostname(); // may output e.g,: sandie
?>
64

echo gethostname(); // may output e.g,: sandie
?>
65

echo gethostname(); // may output e.g,: sandie
?>
66

Richard York ¶

Stefano (Thông tin tại Sarchittu Dot Org) ¶

echo gethostname(); // may output e.g,: sandie
?>
68

11 năm trước

13 năm trước

echo gethostname(); // may output e.g,: sandie
?>
69

echo gethostname(); // may output e.g,: sandie
?>
70

echo gethostname(); // may output e.g,: sandie
?>
71

Danieltahar ¶

13 năm trước

echo gethostname(); // may output e.g,: sandie
?>
73

2 năm trước

5 năm trước

echo gethostname(); // may output e.g,: sandie
?>
74

Tom ¶

10 năm trước

echo gethostname(); // may output e.g,: sandie
?>
75

picov tại e-link dot nó ¶

Stefano (Thông tin tại Sarchittu Dot Org) ¶

echo gethostname(); // may output e.g,: sandie
?>
76

11 năm trước

Danieltahar ¶

echo gethostname(); // may output e.g,: sandie
?>
77

echo gethostname(); // may output e.g,: sandie
?>
78

echo gethostname(); // may output e.g,: sandie
?>
79

2 năm trước

13 năm trước

echo gethostname(); // may output e.g,: sandie
?>
80

echo gethostname(); // may output e.g,: sandie
?>
81

echo gethostname(); // may output e.g,: sandie
?>
82

echo gethostname(); // may output e.g,: sandie
?>
83

Làm cách nào để tìm tên máy chủ của tôi trong PHP?

Hàm gethostName () trả về tên máy chủ cho máy cục bộ.gethostname() function returns the host name for the local machine.

$ _ Máy chủ http_host là gì?

$ _Server ['http_host'] trả về tiêu đề máy chủ từ yêu cầu hiện tại.$ _Server ['http_referer'] trả về URL hoàn chỉnh của trang hiện tại (không đáng tin cậy vì không phải tất cả các tác nhân người dùng đều hỗ trợ nó)Returns the Host header from the current request. $_SERVER['HTTP_REFERER'] Returns the complete URL of the current page (not reliable because not all user-agents support it)

Làm cách nào để tìm tên máy chủ Linux của tôi?

Tìm tên máy tính trên Linux..
Mở một thiết bị đầu cuối.Để mở một thiết bị đầu cuối trong Ubuntu, chọn các ứng dụng -> Phụ kiện -> Terminal ..
Nhập tên máy chủ tại dòng lệnh.Điều này sẽ in tên máy tính của bạn trên dòng tiếp theo ..

Làm cách nào để khởi động một máy chủ PHP cục bộ?

Trong phần này, chúng tôi sẽ trải qua một vài lệnh đơn giản cho máy chủ web PHP ...
Bắt đầu một máy chủ PHP -S localhost: 8000.....
Chỉ định một tài liệu thư mục gốc PHP -S localhost: 8000 -t foo/ ....
Sử dụng tệp bộ định tuyến PHP -S LocalHost: 8000 Bộ định tuyến.....
Bước 1: Tải xuống Pchart Curl -Lok http://www.pchart.net/release/pchart2.1.4.tar ..