/    Sign up×
Community /Pin to ProfileBookmark

Cant figure out. Possible bug?

Ive been trying to figure out a solution to this problem for hours but i cant figure it out. i think it may be a bug, but its driving me crazy. code is below with an explanation at the source of the problem.

// check to see if var ‘m’ is of valid syntax and a proper month
if(isset($_GET[‘m’])) {
$validMonths=range(1, 12);
if(!in_array($_
GET[‘m’], $validMonths)) {
// not a valid month
header(‘Location: home.php’);
}
}

// check to see if var ‘y’ is of valid syntax
if(isset($_GET[‘y’])) {
// here is where it messes up. if the below statement is ‘true’, php for some reason skips the header() and continues. the problem with it continuing is that when it gets to the condition to check if the $_
GET[‘y’] is a valid year, it runs an infinite loop on the else header() because it cant recognize a valid numerical year. the real funny thing is, if you comment out the last 2 header() in the “to far in the future” and “to far in the past”, then the troubled if else statement works…
if(!is_numeric($_GET[‘y’])) {
header(‘Location: home.php’);
}

// check to see if @param ‘y’ is a proper month
$validYear=range(2008-5, 2008+5);
if(!in_array($_GET[‘y’], $validYear)) {
if($_GET[‘y’]<(2008-5)) {
// to far in the past
header(‘Location: home.php?c=1&m=1&y=’.($_GET[‘y’]+1).’&msg=1′);
} else {
// to far in the future
header(‘Location: home.php?c=1&m=12&y=’.($_GET[‘y’]-1).’&msg=1′);

}
}

}

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@r_soleJan 28.2008 — Try using the break function straight after the header function.

So it would look like this:
[code=php]
if(!is_numeric($_GET['y'])) {
header('Location: home.php');
break 2;
}
[/code]
Copy linkTweet thisAlerts:
@chazzyJan 28.2008 — or wrap each individual logic item in an else.
×

Success!

Help @hrysax spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...