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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:41:47+00:00 2026-06-07T05:41:47+00:00

I am creating pages that are dependent on a query in the url (eg

  • 0

I am creating pages that are dependent on a query in the url (eg europe.php?country=france). I am aware that it will be useful to re-write theses as europe.php/france with htaccess for SEO etc but what if that page is accessed without the query string?

I am using php to $_GET the query, so if I access the page without the query I get ‘var=;’ ie, it is empty (and retrieves an error). I’m trying to use an if statement to check if the $_GET retrieves nothing but am unsure if this is the right thing to do.

So: how do I check for an un-retrieved var so I can set a default?
Or: am I going about this the wrong way?

  • 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-07T05:41:48+00:00Added an answer on June 7, 2026 at 5:41 am

    If you know the index into $_GET, use isset():

    $country = 'default';
    if( isset( $_GET['country'])) {
        $country = $_GET['country'];
    }
    

    This will only test if the country parameter was passed, but it could have been set to an empty string. If this is invalid input, you can combine the check using empty():

    $country = 'default';
    if( isset( $_GET['country']) && !empty( $_GET['country'])) {
        $country = $_GET['country'];
    }
    

    You can condense this into one line and save the result to a variable $country using the ternary operator, like so:

    $country = (isset( $_GET['country']) && !empty( $_GET['country'])) ? $_GET['country'] : 'default';
    

    Finally, you can check if you got absolutely no $_GET parameters by calling count() on $_GET:

    if( count( $_GET) == 0) {
        die( "No parameters - Invalid input!");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website that right now, runs by creating static html pages from
I'm creating a code that gets image's urls from any web pages, the code
I'm creating a WP theme that will have two sections midway down the page.
I am creating dependent drop downs using Struts2 jquery. The problem is that getLobList()
I'm creating a new plugin for a jruby on rails application that will eventually
I'm creating a set of archive pages that are specified by year and month.
I'm creating a product page that requires the price to update when the quantity
I am creating a jQuery Mobile page that has two select menu's, one is
I'm creating an asp.net page that uses the google map api. The page loads
I'm creating a set of search panes that allow users to tweak their results

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.