Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8815439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:22:43+00:00 2026-06-14T04:22:43+00:00

PHP newbie here.. I am trying to create a function where the user is

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T04:22:44+00:00Added an answer on June 14, 2026 at 4:22 am

    Since the url is exploded, you get an array like:
    $url[ 0 ] = "http:"
    $url[ 1 ] = "SOME_STRING" and so on.
    You need to check what is the index of the wanted string in your url array and return it.
    Like return $url[ 2 ] or whatever the index is.

    UPDATE

    function custom_add_to_cart_redirect() {
        $url = explode('/', substr($_SERVER['HTTP_REQUEST'], 1));
        print_r( $url );
    }
    

    The print_r( $array ) shows the $array structure including indices and values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a newbie to sql and am trying to follow this example here: http://net.tutsplus.com/tutorials/php/a-better-login-system/
PHP newbie here, I can't understand what I'm doing wrong here. I'm trying to
PHP/MySQL newbie here. I managed to develop a web page that displays info from
Am Newbie here.Am Beginner in php.I Create a sample Reg form.Here i want to
I need a little help. Im a newbie. I'm trying to create a php
Newbie here trying to maintain a PHP website for some charity organization, but cannot
A really php newbie here, sorry if the question is too simple. I’m following
a bit of a PHP / MySQL newbie here... I've been building a PHP-based
Im sure this is simple but newbie here. I have 5 URLS cards.php&type=one cards.php&type=two
Im a newbie ih php.Im trying to show drop down list values from database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.