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 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 link that looks like this: <a href=/site/cdb/index.php?adinfo=272>Company Inc.</a> I want to
I want to have a link that is like this change(en-NZ) which shows the
I have found some info on the subject ( like this link) , but
I have a link that looks like this: <p class=half_text> <?php echo $upvotes; ?>
If I have a link like this: <a data-btn=login></a> If I wished to select
I have a link that looks like this: <a onclick=myLightbox rel=lightbox href=image.jpg title=> I
I have a html like this: <html> <head> <link rel=stylesheet type=text/css media=all href=style.css> </head>
i have multiple strings containing a link like: <A HREF=http://www.testings2>testings2</A> <A HREF=http://www.blabla>blabla</A> <A HREF=http://www.gowick>gowick</A>
I have a link that I want to look like a button so I
I have a href link and I would like it to be clicked when

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.