base url in php

Solutions on MaxInterview for base url in php by the best coders in the world

showing results for - "base url in php"
Axel
08 Nov 2018
1Try this:
2
3<?php echo "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; ?>
4Learn more about the $_SERVER predefined variable.
5
6If you plan on using https, you can use this:
7
8function url(){
9  return sprintf(
10    "%s://%s%s",
11    isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
12    $_SERVER['SERVER_NAME'],
13    $_SERVER['REQUEST_URI']
14  );
15}
16
17echo url();
18#=> http://127.0.0.1/foo
19Per this answer, please make sure to configure your Apache properly so you can safely depend on SERVER_NAME.
20
21<VirtualHost *>
22    ServerName example.com
23    UseCanonicalName on
24</VirtualHost>
25NOTE: If you're depending on the HTTP_HOST key (which contains user input), you still have to make some cleanup, remove spaces, commas, carriage return, etc. Anything that is not a valid character for a domain. Check the PHP builtin parse_url function for an example.
Bartholomew
12 Aug 2018
1<?php echo "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; ?>
2
queries leading to this page
php base uriphp url basenamebase url path in phpsyntax for getting base url in phphow to get the base url of a website in phpphp basename on url get base url from another page phpphp get base url from 24serverphp get base uriphp use base urlhow to get base url of any function using phpget base url 24this 3epageurl phpphp create base urlget base url in phpdynamic base url phphow to get the base url in phpphp get url basenamebase64 url phpphp set base url 3c 3fphp echo base urlphp echo base urlbase url syntax in phpget base url from url phpbase url 28 29 in phpwhat is base url in phpcosntant base url in phpbase url in phpphp base url php get url basephp base64 urldefine base url phpecho base url phphow to get base url usin phpbase link phpphp get base urlbase uri phpget base name from url in phpphp base urichange base url php 3c 3fphp echo base url 3b 3f 3ephp get base url from stringbase url in php includephp how to get base urlcreate base url phphow can use base url use in phpbase of url phpbase url phpphp find base url 3c 3fphp echo base url 28 29 3b 3f 3ehow to get base url oin phpphp echo base url 28 29php server base urlphp get base uri from stringbase uri phpbase url 28 29link base url in phphow tp het the base url of a website in php 3c 3fphp echo base url 28 29 3b 3f 3eget the base url phpget the baseurl in phpbase url php in javascriptbase url in phpaccess base url in base url phphow to get base url in phpget base url phpget the base url in phpbase url phpphp get base url 3c 3fphp get base urlphp baseurlphp get base url with httpget base url from string phpphp echo base url 28 29 3c 3fphp echo base url 28 29 3f 3eserver base url phphow to set base url in phpset base url in phpget base url from a url phphow to find base url in phpfunction get base url in phphow to get base url in phpbase url example phpdefine base url in phpget base url phphow to make base url in phpphp base url 24base url phpurl 28 29 php function base pathbase64 url in phpphp request base urlphp set the base urlbaseurl phphow create base url in phpbase url in php