Question: I have webpages with URL <http://siteurl/directory/onemore/>$fileID.php 
I am trying to extract just the $fileID and after that use 

```
$query = $mysqli->query("SELECT * FROM tablename WHERE ID = $fileID");
$rows = mysqli_fetch_array($query);
$hits = $rows['HITS'];
$hits = $hits + 1;
$query = $mysqli->query("UPDATE tablename SET HITS = $hits WHERE ID = $fileID");
echo 'Total hits on page'.$hits.'';

```

I can't figure out how to get just the $fileID part and wanted to ask is the rest of my procedure correct? 

**EDIT**

With the code above hits get stuck at one. I was thinking that after each page refresh they will update to +1.

Answer: 
You can determine the $fileId like this:

```
/* $_SERVER['PHP_SELF'] results to e.g. '/directory/onemore/5.php' */
/* basename(...) results to e.g. '5.php' */
$fileName = basename($_SERVER['PHP_SELF']);
/* take the text before the last occurrence of '.' */
$fileID = substr($fileName, 0, strrpos($fileName, '.'));

$query = $mysqli->query("UPDATE tablename SET HITS = HITS + 1 WHERE ID = $fileID");

$query = $mysqli->query("SELECT * FROM tablename WHERE ID = $fileID");
$rows = mysqli_fetch_array($query);
$hits = $rows['HITS'];
echo 'Total hits on page'.$hits.'';

```
Try this:

```
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';

print_r(parse_url($url));

echo parse_url($url, PHP_URL_PATH);
?>

```

> 
> Output
> 
> 
> 

```
Array
(
    [scheme] => http
    [host] => hostname
    [user] => username
    [pass] => password
    [path] => /path
    [query] => arg=value
    [fragment] => anchor
)

```

See, if that helps.