In my LAMP application I am using Javascript for form validation but of course internet users can switch Javascript off in their browser so I also validate the form data on the server using a PHP function.
Does anyone know if there is some clever way to reuse my Javascript validation on the server so as to avoid writing a PHP version?
It’s a little difficult to tell without knowing how you’ve constructed your application, but it’s unlikely you’ll be able to recycle your JavaScript on the server side. On the other hand, if you construct a lightweight, fast php validation tool you can use server-side validation via XHR instead of (a lot of the) JavaScript, and save yourself some redundancy the other direction.
However, that way’s bound to be slower, so the best combination of user experience and security will probably come from having some redundancy in your validation.