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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:56:10+00:00 2026-05-30T08:56:10+00:00

maybe a very simple question, however I have no idea what I do wrong,

  • 0

maybe a very simple question, however I have no idea what I do wrong, maybe someone could help me?

There is a GET-variable that contains the year and I want to check if it is actually a valid format and also not in the past, meaning the current year or later. What I did till now was:

$current_year=date('Y',$today);

(is_int(intval($_GET['year'])) AND $_GET['year']>$current_year) ? $year=$_GET['year'] : $year=$current_year;

The function intval() returns as it should 0 or 1 as stated in the php.net manual, if the GET-var is a not an integer, e.g. string “abc”.

However, if $_GET[‘year’] contains “abc” which is then converted into 0 and should not be > 2012, $year is not 2012!?

Any hint would be highly appreciated and thank you in advance!


EDIT:

Thank you for all your great answers! I’ve tried to consider all of them, and this works now perfectly for me:

if (ctype_digit($_GET['year'])) { ($_GET['year'] > $current_year && $_GET['year']<=($current_year+2)) ? $year=$_GET['year'] : $year=$current_year;} else {$year=$current_year;}

As I only need the next 2 years in the future, I added this… thank you for the hint to check if it is only 4 digits, deceze! 🙂

  • 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-30T08:56:11+00:00Added an answer on May 30, 2026 at 8:56 am

    intval will mangle anything into an int, even if just into 0, which means is_int is consequently always true. is_int(intval()) is therefore pointless. $_GET values will always be strings, even if they only contain numbers. Therefore you probably want to check using ctype_digit, which tells you whether all characters in the string are numbers. So your check should look something like:

    if (ctype_digit($_GET['year']) && $_GET['year'] > $current_year) ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe, it's very simple question but I couldn't get the answer. I've been searching
I have maybe very very Simple Question: Where i can find documentation about expressions
Maybe a very simple question. How can I put in this code <Query> <Where>
This may be very simple question,But please help me. i wanted to know what
I have what may be a very simple question. I want to process a
I'm not very good at regex but maybe there's a simple way to achieve
My question is very simple: In flex3, is there a way to load an
I have a java threads related question. To take a very simple example, lets
maybe this is a very simple question, but forgot the answer about it because
I have a very simple question (I guess!) I used to work with Scriptaculous

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.