Home
Recent Q&A
Java
Cloud
JavaScript
Python
SQL
PHP
HTML
C++
Data Science
DBMS
Devops
Hadoop
Machine Learning
Azure
Blockchain
Devops
Ask a Question
PHP get domain name -how to fix it?
Home
PHP
PHP get domain name -how to fix it?
0
votes
asked
Feb 2, 2021
in
PHP
by
SakshiSharma
PHP get domain name -how to fix it?
I want to get the domain name for where the script is running. How can that be done with PHP? I see that $_SERVER['HTTP_HOST'] as well as $_SERVER['SERVER_NAME'] contain this information. Will that variable always work and should I use one over the other?
#php-domain
php
Please
log in
or
register
to answer this question.
1
Answer
0
votes
answered
Feb 2, 2021
by
SakshiSharma
Recommended using HTTP_HOST, and falling back on SERVER_NAME only if HTTP_HOST was not set. He said that SERVER_NAME could be unreliable on the server for a variety of reasons, including:
no DNS support
misconfigured
behind load balancing software
Your comment on this answer:
Email me at this address if a comment is added after mine:
Email me if a comment is added after mine
Privacy: Your email address will only be used for sending these notifications.
Related questions
+1
vote
Q: How to call a JavaScript function from PHP?
asked
Feb 2, 2021
in
PHP
by
SakshiSharma
php
php-echo
javascript-php
0
votes
Q: How to pop an alert message box using PHP?
asked
Feb 2, 2021
in
PHP
by
SakshiSharma
#pop-up
php-popup
popup-box
php-popup-box
javascript
php
messagebox
0
votes
Q: How to delete image from folder PHP?
asked
Feb 1, 2021
in
PHP
by
SakshiSharma
#delete-image
image-php
php
image
delete-image-php
+1
vote
Q: PHP stands for -
asked
May 11, 2022
in
PHP
by
sharadyadav1986
php
+1
vote
Q: Advanced Multiple Choice Questions on PHP
asked
Jun 23, 2019
in
PHP
by
SakshiSharma
#php-php
#php-server-monitor-script
#php-language
#php-programmer
advanced
multiple
choice
questions
on
php
0
votes
Q: How to Install NGINX, PHP, MySQL, SSL & WordPress on Ubuntu
asked
May 14, 2023
in
NGINX
by
john ganales
install
nginx
php
mysql
ssl
&
wordpress
ubuntu
0
votes
Q: How do you leverage Aptana Studio’s built-in support for PHP development
asked
Feb 26
in
Aptana
by
rajeshsharma
php
development
0
votes
Q: How to get the length of string in PHP?
asked
Jun 6, 2020
in
PHP
by
SakshiSharma
#php-string-length
#length-string-php
0
votes
Q: How can we get IP address of a client in PHP?
asked
Jun 6, 2020
in
PHP
by
Robindeniel
#php-get-ip-address
#php-client-ip-address
#php-address-ip
+1
vote
Q: Which of the following function is used to get the ASCII value of a character in PHP?
asked
May 13, 2022
in
PHP
by
john ganales
ascii-value
...