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

  • Home
  • SEARCH
  • 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 3792298
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:36:03+00:00 2026-05-19T12:36:03+00:00

when i have a link like this which can be longer but i’ve put

  • 0

when i have a link like this which can be longer but i’ve put a short version for my question.

index.php?product=jeans&gender=male&lang=english

if the selection for the language looked like this

<select name="lang">
<option value="<?=$url;?>">english</option>
<option value="<?=$url;?>">spanish</option>
</select>

for the url variable i’ll have something like this.

<?php

if(isset($_GET['lang']))
{
    $lang = $_GET['lang'];
    if(isset($_GET['product']) && !isset($_GET['gender']))
    {
        $product = $_GET['product'];
        $url = "index.php?product=".$product."&lang=".$lang;
    }
    elseif(isset($_GET['product']) && isset($_GET['gender']))
    {
        $product = $_GET['product'];
        $gender = $_GET['gender'];
        $url = "index.php?product=".$product."&gender=".$gender."&lang=".$lang;
    }
}
elseif(!isset($_GET['lang']))
{
    if(isset($_GET['product']) && !isset($_GET['gender']))
    {
        $product = $_GET['product'];
        $url = "index.php?product=".$product."&lang=english";
    }
    elseif(isset($_GET['product']) && isset($_GET['gender']))
    {
        $product = $_GET['product'];
        $gender = $_GET['gender'];
        $url = "index.php?product=".$product."&gender=".$gender."&lang=english";
    }
}

?>

as you can see it gets very messy. just to make sure the end-user is always on his/her correct page no matter what change is done in the param. what is the best way of doing this? im sick of checking soo much data just to make sure the end-user is on the correct page. how would you have had done this?

note: i havent written any functions to clean the gets i just wanted to write something clean so it is easy to read.

  • 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-19T12:36:04+00:00Added an answer on May 19, 2026 at 12:36 pm
    function defaultOrGet($param, $default = "") {
        return ( isset($_GET[$param]) ? $_GET[$param] : $default );
    }
    
    
    $lang = defaultOrGet('lang', 'english');
    $product = defaultOrGet('product');
    $gender = defaultOrGet('gender');
    
    $url = 'index.php?'
    
    if (!empty($product)) {
        $url .= 'product=' . $product . '&lang=' . $lang;
    
        if (!empty($gender)) {
            $url .= '&gender=' . $gender;           
        }
    }
    // else $url point to index.php
    

    something like that.

    See also: http_build_query

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

Sidebar

Related Questions

I have a php which generates an xml file and prints it on screen.
I've got a PHP database class which connects to MySQL and wraps up all
I have a fairly standard ASP.Net web application which is used via mobile safari
I want to create file-links to open an external editor from firefox. I have
I have created a model POCO class called Recipe ; a corresponding RecipeRepository persists
I an writing a website that will have multiple skins. Each skin has its
I have a form with various fields the user need to feel out with
I am helping a friend with a website for her non-profit organization. The main
I need to make an effect similar to the Android effect when you slide
My android application downloads articles formatted with HTML tags and displays them in the

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.