Very simple but confusing PHP problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jayfield
Forum Newbie
Posts: 3
Joined: Tue Apr 14, 2009 7:23 am

Very simple but confusing PHP problem

Post 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.
jayfield
Forum Newbie
Posts: 3
Joined: Tue Apr 14, 2009 7:23 am

Re: Very simple but confusing PHP problem

Post 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?
jayfield
Forum Newbie
Posts: 3
Joined: Tue Apr 14, 2009 7:23 am

Re: Very simple but confusing PHP problem

Post 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.
User avatar
greyhoundcode
Forum Regular
Posts: 613
Joined: Mon Feb 11, 2008 4:22 am

Re: Very simple but confusing PHP problem

Post 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!
Post Reply