CodeSOD: The Variable Toggle

This post was originally published on this site

The Daily WTF

A common class of bad code is the code which mixes server side code with client side code. This kind of thing:

<script> <?php if (someVal) { ?> var foo = <? echo someOtherVal ?>; <?php } else { ?> var foo = 5; <?php } ?> </script>

We’ve seen it, we hate it, and is there really anything new to say about it?

Well, today’s anonymous submitter found an “interesting” take on the pattern.

<script> if(linkfromwhere_srfid==’vff’) { <?php $vff = 1; ?> } </script>

Here, they have a client-side conditional, and based on that conditional, they attempt to set a variable on the server side. This does not work. This cannot work: the PHP code executes on the server, the client code executes on the client, and you need to be a lot more thoughtful about how they interact than this.

And yet, the developer responsible has

To read the full article click on the 'post' link at the top.