Tuesday, July 14

Get Just The Path from a Request in PHP


It can be a little tricky to get just the path of a request in PHP.
$_SERVER['REQUEST_URI'] includes the query string.
$_SERVER['SCRIPT_NAME'] may return index.php instead of the request if you’re using a CMS like WordPress which rewrites URLs.

The most reliable method I’ve found for returning only the path without the query string uses PHP’s built in parse_url() function:

<?php

    $path_only = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);

?>

3 comments:

  1. Nice information and Thank You
    if you don't mind please visit my Website MPOGG
    it talks about Slot Online and other fun things.
    Also visit our patner website Asiaking168 the best slot in Asia also known as asia slot
    Thank You

    ReplyDelete
  2. mpo4d is a good engine from mpo. This entertainment business provide by TOWERKLUB, you can do mpo4d login in here

    ReplyDelete