Explode URL Query String Issue

Posted by Ian McAbee on Stack Overflow See other posts from Stack Overflow or by Ian McAbee
Published on 2012-11-10T00:12:51Z Indexed on 2012/11/10 5:00 UTC
Read the original article Hit count: 146

Filed under:
|
|
|

PHP newbie here.. I am trying to create a function where the user is redirected back to the previous page after adding an item to their cart. However, when they are redirected back with the code below it leaves a duplicate of the directory (ie. example.com/catalog/garden-tools/garden-tools

function custom_add_to_cart_redirect() {
    $_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
    $url = explode('/', rtrim($_SERVER['REQUEST_URI_PATH'], '/'));
    return $url[3];
}

A print_r reveals the following:

Array ( [0] => [1] => thefarmshop [2] => catalog [3] => garden-tools [4] => gardening-glove )

What could the issue be?

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays