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 6836813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:24:05+00:00 2026-05-26T23:24:05+00:00

I use the Current url function to get the current link when user changing

  • 0

I use the “Current url” function to get the current link when user changing page language

$uri = explode('&', $_SERVER['REQUEST_URI']);
$uri = $uri[0];

$url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$uri : "http://".$_SERVER['SERVER_NAME'].$uri;

Problem is, when I have a link like this:

http://127.0.0.1/index.php?id=shop&id2=13&lang=lt

id2, of course, disappears. What can I do about this? It is possible if id2 is set to use explode with a second & or something like this?

  • 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-05-26T23:24:05+00:00Added an answer on May 26, 2026 at 11:24 pm

    You can use the parse_url function, here is an example:

    $uri = parse_url( $_SERVER['REQUEST_URI']);
    $protocol = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://';
    $url = $protocol . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . '?' . ( isset( $uri['query']) ?  $uri['query'] : '');
    

    I did not see in your code where you get the script’s filename, so I used $_SERVER['SCRIPT_NAME'].

    Edit: My mistake, I did not see that you need to manipulate / remove the last $_GET parameter. Here is an example on how to do that using a method similar to the above in conjunction with parse_str. Note that this method will work regardless of the location of the lang parameter, it does not have to be the last one in the query string.

    $protocol = !empty($_SERVER['HTTPS']) ? 'https://' : 'http://';
    
    $params = array();
    if( isset( $_SERVER['QUERY_STRING']) && !empty( $_SERVER['QUERY_STRING']))
    {
        parse_str( $_SERVER['QUERY_STRING'], $params);
        $params['lang'] = 'anything';
        // unset( $params['lang']); // This will clear it from the parameters
    }
    
    // Now rebuild the new URL
    $url = $protocol . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . ( !empty( $params) ? ( '?' . http_build_query( $params)) : '');
    

    Thanks to @Yzmir Ramirez for an improvement in the second version that eliminates the extraneous call to parse_url.

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

Sidebar

Related Questions

I use cURL library to get the content of current URL. So I wonder,
I need a helper function to get the current language code. I want to
As we know, we can use the function `file_get_contents(url)` in PHP to get content
Say I use glRotate to translate the current view based on some arbitrary user
I have the following Helper that gets the FULL url of the current page
I am submitting a normal <form method=get> element to the current url... It's part
Short and sweet, Is it ok to use (current version) Ruby 1.9.1 with Rails
I need to use the current library name explicitly in a CL program. CHGVAR
Is there a library out there which I can use in my current ASP.NET
How to do it? I don't want to use this: HttpContext.Current.Server.MapPath Is there a

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.