Get current domain
Try using this:
$_SERVER['SERVER_NAME']
Or parse:
$_SERVER['REQUEST_URI']
Reference: apache_request_headers()
Get The Current Domain Name With Javascript (Not the path, etc.)
How about:
window.location.hostname
The location
object actually has a number of attributes referring to different parts of the URL
Get the current URL with JavaScript?
Use:
window.location.href
As noted in the comments, the line below works, but it is bugged for Firefox.
document.URL
See URL of type DOMString, readonly.
How to get the host URL using JavaScript from the current page
// will return the host name and port
var host = window.location.host;
or possibly
var host = window.location.protocol + "//" + window.location.host;
or if you like concatenation
var protocol = location.protocol;
var slashes = protocol.concat("//");
var host = slashes.concat(window.location.host);
// or as you probably should do
var host = location.protocol.concat("//").concat(window.location.host);
// the above is the same as origin, e.g. "https://stackoverflow.com"
var host = window.location.origin;
If you have or expect custom ports use window.location.host
instead of window.location.hostname
How to get current domain name in ASP.NET
Using Request.Url.Host
is appropriate - it's how you retrieve the value of the HTTP Host:
header, which specifies which hostname (domain name) the UA (browser) wants, as the Resource-path part of the HTTP request does not include the hostname.
Note that localhost:5858
is not a domain name, it is an endpoint specifier, also known as an "authority", which includes the hostname and TCP port number. This is retrieved by accessing Request.Uri.Authority
.
Furthermore, it is not valid to get somedomain.com
from www.somedomain.com
because a webserver could be configured to serve a different site for www.somedomain.com
compared to somedomain.com
, however if you are sure this is valid in your case then you'll need to manually parse the hostname, though using String.Split('.')
works in a pinch.
Note that webserver (IIS) configuration is distinct from ASP.NET's configuration, and that ASP.NET is actually completely ignorant of the HTTP binding configuration of the websites and web-applications that it runs under. The fact that both IIS and ASP.NET share the same configuration files (web.config
) is a red-herring.
Is there any solution for getting current domain name by Reactjs?
This isn't React specific.
Just look at window.location
:
alert(window.location.hostname)
Related Topics
Use Openssl_Encrypt to Replace Mcrypt for 3Des-Ecb Encryption
Rest API Authorization & Authentication (Web + Mobile)
Laravel Named Route for Resource Controller
How to Run a Cronjob Every X Minutes
How to Create a Twig Custom Tag That Executes a Callback
How to Customize Fos Userbundle Urls
PHP Get Both Array Value and Array Key
Malformed Utf-8 Characters, Possibly Incorrectly Encoded' in Laravel
Bind Param with Array of Parameters
How to Convert Iso8601 to Date Format in PHP
MySQL - Insert Date Range into Date Columns If Dates Don't Overlap with Existing Ones
How to Run Single Test Method with PHPunit
Is "Set Character Set Utf8" Necessary
How to Execute Raw Queries with Laravel 5.1
Can Servers Block Curl Requests
How to Display Currency in Indian Numbering Format in PHP
How to Define a Laravel Route with a Parameter That Contains a Slash Character