Page 1 of 1

Very simple but confusing PHP problem

Posted: Tue Apr 14, 2009 7:27 am
by jayfield
I've been coding simple PHP web apps for years and i've come across a really confusing error.

I'm trying to redirect back to a form if they haven't provided the acceptable amount of characters.

So my question is.... Why does this code work:

Code: Select all

if(strlen($cvObjective) < $minCvObective){
    $charAmount = strlen($cvObjective);
    header("Location: buildCV.php?error=2&charAmount=$charAmount&cvObjective=$cvObjective");
    break;
}
... and yet this doesn't:

Code: Select all

if(strlen($cvObjective) > $maxCvObective){
    $charAmount = strlen($cvObjective);
    header("Location: buildCV.php?error=3&charAmount=$charAmount&cvObjective=$cvObjective");
    break;
}
$maxCvObective = 500
$minCvObective = 50

The top code redirects but the bottom does not!!! Have I missed something really obvious?

Thanks in advance.

Re: Very simple but confusing PHP problem

Posted: Tue Apr 14, 2009 7:35 am
by jayfield
Oh dear... i think it's because i can only send 512 max characters back via the GET appending URL method.

What is the best way to deal with this?

Re: Very simple but confusing PHP problem

Posted: Tue Apr 14, 2009 7:52 am
by jayfield
I have solved it by lobbing the long string in a temp session variable but there has to be a more elegant solution without using Javascript on the front-end.

Re: Very simple but confusing PHP problem

Posted: Tue Apr 14, 2009 8:07 am
by greyhoundcode
Unrelated to any issues with your logic, but I believe it is best practice to use absolute URLs when redirecting with header().

EDIT- Think I misread your post first time, so I am editing appropriately!