Can I let PHP know that a user does not have javascript enabled?
Top results on a google search:
http://www.inspirationbit.com/php-js-detection-of-javascript-browser-settings/
Sure, just use an AJAX call to... ;)
I can't really think of a way to do this without direct user interaction. If you have some form/link that your user is going to submit to the server anyway, you could have a section of it (some <input
element, or add an extra URL parameter to a link) within <noscript>
tags such that that data only gets submitted by the user when Javascript is off.
You can have JavaScript let PHP know by setting a cookie once the user enters your page, for example. You won't know until the next request to the server, though.
You could also have JavaScript do a request with XMLHttpRequest
that tells PHP to set a session variable. Still, you won't know until the next request.
What are you trying to do? There might be other solutions to your problem as well.
Start by assuming javascript is off or not available, then send the client some HTML which includes this
<script>
window.location = "http://www.mysite.com/javascript.php?enabled=true";
</script>
<noscript>
possible tell the user the consequences of not having javascript enabled
</noscript>
In the javascript.php script, you can store in the session that the client supports javascript. You could also do with with an XMLHTTPRequest object rather than a straight redirect.
However, depending on your application, it's almost always better to build your app to work without Javascript, perhaps less efficiently, and then have your script kick in and augment the basic version with enhanced functionality. That way, you don't need to detect it, you just use it if its available.