Explode URL Query String Issue
- by Ian McAbee
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?