How can i get domain link in php?
For example with the function above, it works fine if I work with the same directory, but if I make a sub directory, and work in it, it will give me the location of the sub directory also for example. I just want Or how could I fix my function/code to get the main url only? Thanks. asked Jun 19, 2013 at 20:56
1 Use
answered Jun 19, 2013 at 21:01
Bad WolfBad Wolf 7,9564 gold badges33 silver badges43 bronze badges 4 You could use PHP's
answered Jun 19, 2013 at 21:00 3 Shortest solution:
answered May 11, 2017 at 9:08
barbushinbarbushin 5,1135 gold badges35 silver badges43 bronze badges 6
answered May 6, 2016 at 11:17
JasmeenJasmeen 8569 silver badges16 bronze badges 3 Use
Here is another shorter option:
answered Jun 19, 2013 at 21:01
Get Off My LawnGet Off My Lawn 31.8k34 gold badges157 silver badges299 bronze badges 1 Step-1First trim the trailing backslash (/) from the URL. For example, If the URL is http://www.google.com/ then the resultant URL will be http://www.google.com
Step-2If scheme not included in the URL, then prepend it. So for example if the URL is www.google.com then the resultant URL will be http://www.google.com
Step-3Get the parts of the URL.
Step-4Now remove www. from the URL
Your final domain without http and www is now stored in $domain variable. Examples: http://www.google.com => google.com https://www.google.com => google.com www.google.com => google.com http://google.com => google.com answered Nov 28, 2017 at 9:22
1 2 lines to solve it
answered Apr 20, 2019 at 20:35
FadiFadi 2272 silver badges6 bronze badges 1
answered May 22, 2019 at 5:22
Aasif khanAasif khan 1311 silver badge8 bronze badges Use this code is whork :
answered Jan 11, 2021 at 0:02
lookly Devlookly Dev 3073 silver badges4 bronze badges 1 This works fine if you want the http protocol also since it
could be http or https. answered Apr 18, 2020 at 7:52
RudolphRudolph 1391 silver badge7 bronze badges Please try this:
I hope this will help you.
Ismail RBOUH 9,9942 gold badges23 silver badges36 bronze badges answered Jul 14, 2016 at 14:49
CharlesCharles 3102 silver badges8 bronze badges 1 Tenary Operator helps keep it short and simple.
answered Oct 2, 2018 at 17:09
OluwaseyeOluwaseye 6817 silver badges19 bronze badges 1 If you're using wordpress, use get_site_url:
answered May 13, 2020 at 1:44
ElronElron 1,0601 gold badge11 silver badges20 bronze badges How can I get link from website in PHP?Create a PHP variable that will store the URL in string format. Check whether the HTTPS is enabled by the server. If it is, append “https” to the URL string. If HTTPS is not enabled, append “http” to the URL string.
How do I find my PHP URL?Answer: Use the PHP $_SERVER Superglobal Variable
You can use the $_SERVER built-in variable to get the current page URL in PHP. The $_SERVER is a superglobal variable, which means it is always available in all scopes.
How can I get host in PHP?The gethostname() function returns the host name for the local machine.
|