Question: Is there a way in PHP to assign or display a variable if the page URL is equal to a specific value?

I have a site with 100 pages. Each page has a list of variables that are echoed through it based on `$page` variable. I would like to have this variable assigned on the fly. I want to be able to set a variable, 1-100 for example, based on page URL.

If page URL is equal to 

> 
> www.example.com/page/dog
> 
> 
> 

set the `$page` variable for page to `dog`.

If page URL is equal to 

> 
> www.example.com/page/cat
> 
> 
> 

set the `$page` variable for page to `cat`.

So on and so forth. Once the variable is set certain things will happen. In order for the correct information to be displayed I need the correct page variable to be set. 

Below is ALL the code that exists on each page.

```
<?php $page = 'example1'; ?> 
<?php include '../includes/core/overall/header.php'; ?>
<?php include '../includes/core/overall/footer.php'; ?>

```

Answer: 
Use the following:

```
$page = basename($_SERVER['SCRIPT_FILENAME']);

```
Take advantage of HTTP's pathinfo.

### $DOCUMENT\_ROOT/page/index.php:

```
<?
  $page = substr($_SERVER['PATH_INFO'], 1);
   ...

```