Post a variable with value 0 – PHP



I have a program and I need to post a variable to a page. On the target page I need to test to see if a variable has been posted and redirect the user if it hasn’t.
Sometimes the value of the variable needs to be the number zero (0) but when I post it, then it does the redirect. Is there I way I can make it tell the difference between the post zero and a non-posted value.

The value is posted through a standard HTML form and the number crunching is done via PHP.

if ($_SESSION['value']=="")
if (!($_POST['value']))
<script type="text/javascript">

Any help would be greatly appreciated.


In PHP, you can use the isset function to see if a variable is set or not.


question, why writing a JavaScript redirect (that can be turned off) when you can write a PHP redirect?


I knew that Rabbit. I don’t know how I forgot. Thanks. I’ll sort that.

I tried that Dormlilch but it didn’t work for some reason. Are you able to give me the correct code?


I tried that Dormlilch but it didn’t work for some reason.

then what have you tried? what error messages have you got? (note that a PHP redirect does not work after you have printed/echoed something out (and that emits a notice).


Good point. I think I tired it on a different page after I had printed something out and it didn’t work. I used the JavaScript one and then probably decided to use that again, but I should be able to use the php one.
Thanks I’ll sort that out.


I’ve just fixed it with isset andit works so much like a charm I just had to thank you. Brilliant Rabbit.
I’ll try your suggestion next Dormilich.