Hello People
Is there a way to check in PHP whether the user browser supports Javascript?
and if so, how?
thanks
how to check if Javascript is enabled
Moderator: General Moderators
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
I was also thinking if something is available to check whether Javascript is enabled or not it would be very useful.
For instance, I want Javascript validation for stopping unnecessary submission to server side script and for performance; if Javascript is not enabled then I can use my server side validation else I would just let the form fields to pass through without validation.
For instance, I want Javascript validation for stopping unnecessary submission to server side script and for performance; if Javascript is not enabled then I can use my server side validation else I would just let the form fields to pass through without validation.
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
You should always validate server-side, the loophole in that logic is if an attacker writes up their own form to show javascript is enabled, but does not validate the input you could have some SQL injection or worse.raghavan20 wrote:I was also thinking if something is available to check whether Javascript is enabled or not it would be very useful.
For instance, I want Javascript validation for stopping unnecessary submission to server side script and for performance; if Javascript is not enabled then I can use my server side validation else I would just let the form fields to pass through without validation.
It is useful for reducing the number of failed validation requests, and that is about it
Actually, there is another use for it.Jenk wrote:You should always validate server-side, the loophole in that logic is if an attacker writes up their own form to show javascript is enabled, but does not validate the input you could have some SQL injection or worse.raghavan20 wrote:I was also thinking if something is available to check whether Javascript is enabled or not it would be very useful.
For instance, I want Javascript validation for stopping unnecessary submission to server side script and for performance; if Javascript is not enabled then I can use my server side validation else I would just let the form fields to pass through without validation.
It is useful for reducing the number of failed validation requests, and that is about it
As odd as it seems to pair JS with Usability, using JS properly, you can provide very useful feedback to the user on what they are doing wrong when filling out a form. From highlighting fields, to verifying that they've used the correct format, JS can be very useful in form completion.
But I agree about the validation - that should be done server-side, or else you are trusting the user for your security. Never a good idea.