PHP - find the URL of a script that includes the current document

I have a template that I made that sets variables that rarely change, call my headers, call my banner and sidebar, load a variable that displays individual pages, and then call the footer. In one of my headers, I want the URL of the page in the user's address bar. Is there any way to do this?

Currently

<?php
$title = "MySite - Contacts";
include("header.php");
.
.
.
?>
+3
source share
3 answers

The main variables you will interact with are the following:

$_SERVER['REQUEST_URI'] , . /foo/bar $_SERVER['PHP_SELF'] - PHP ( , , include, )

, $_SERVER, :

print_r($_SERVER);

http://php.net/manual/en/reserved.variables.server.php

+2

- ::

function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}

, google.

+1

It seems that $_SERVER['REQUEST_URI']is what you need.

0
source

All Articles