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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:04:33+00:00 2026-06-04T22:04:33+00:00

Possible Duplicate: keeping url parameters during pagination I want to add a parameter to

  • 0

Possible Duplicate:
keeping url parameters during pagination

I want to add a parameter to the current url with php, but how do I know if the url already contains a parameter?

Example:

foobar.com/foo/bar/index.php => foobar.com/foo/bar/index.php?myparameter=5
foobar.com/index.php?foo=7 => foobar.com/index.php?foo=7&myparameter=5

The main problem is that I don’t know if I need to add a “?”.

My code (found it somewhere, but it doesn’t work):

<?php   if(/?/.test(self.location.href)){ //if url contains ?
    $url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]&myparameter=5";
} else {
    $url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]?myparameter=5"; 
}?>
  • 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-04T22:04:34+00:00Added an answer on June 4, 2026 at 10:04 pm

    The URL parameters are received from a global variable called $_GET which is in fact an array. So, to know if a URL contains a parameter, you can use isset() function.

    if (isset($_GET['yourparametername'])) {
        //The parameter you need is present
    }
    

    Afterwards, you can create separate array of such parameter you need to attach to a URL. Like:

    if(isset($_GET['param1'])) {
        \\The parameter you need is present
        $attachList['param1'] = $_GET['param1'];
    }
    if(isset($_GET['param2'])) {
        $attachList['param2'] = $_GET['param2];
    }
    

    Now, to know whether or not, you need a ? symbol, just count this array

    if(count($attachList)) {
        $link .= "?";
        // and so on
    }
    

    Update:

    To know if any parameter is set, just count the $_GET

    if(count($_GET)) {
         //some parameters are set
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What to do when I want to use database constraints but only
Possible Duplicate: What is the fastest XML parser in PHP? I still need to
Possible Duplicate: How to successfully rewrite old mysql-php code with deprecated mysql_* functions? I
Possible Duplicate: Javascript window resize event I want to get an event which is
Possible Duplicate: What are the pros and cons to keeping SQL in Stored Procs
Possible Duplicate: array_splice() for associative arrays How to add an array value to the
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: regex for URL including query string I have a text or message.
Possible Duplicate: thread with multiple parameters How does one thread a sub with two
Possible Duplicate: Opening url in new tab while i am doing window.open(), my page

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.