-3

How to get the current full url in php?

Ex. full url: www.topclinique.ma/list-cliniques.php?t=cliniques&s=0&c=Casablanca

Mariem
  • 39
  • 1
  • 1
  • 10

2 Answers2

3

You can use

$current_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
Jenz
  • 8,280
  • 7
  • 44
  • 77
0

Try this:

if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||  isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}

$current_link = $protocol.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
echo $current_link;
Habibul Morsalin
  • 180
  • 1
  • 11