Re: How do I check if javascript is enabled in PHP?
you use a function called get_browser()
it takes no parameters and anaylzes the HTTP_USER_AGENT
it return an assoctive array
you check "javascript " key and if it is set to 1 then javascript is
enabled
For example:
$results = get_browser();
if ($results["javascript "] == 1) {
echo "You have javascript";
}
One thing you need to now is you must set the browscap.ini in your
php.ini file to the location of you browscap.ini. You can get one at
Re: How do I check if javascript is enabled in PHP?
Benjamin schreef:
you use a function called get_browser()
it takes no parameters and anaylzes the HTTP_USER_AGENT
it return an assoctive array
you check "javascript " key and if it is set to 1 then javascript is
enabled
>
Err: It only indicates if the browser supports javascript, not if it's
enabled or not.
Re: How do I check if javascript is enabled in PHP?
Benjamin wrote:
you use a function called get_browser()
it takes no parameters and anaylzes the HTTP_USER_AGENT
it return an assoctive array
you check "javascript " key and if it is set to 1 then javascript is
enabled
For example:
$results = get_browser();
if ($results["javascript "] == 1) {
echo "You have javascript";
}
>
One thing you need to now is you must set the browscap.ini in your
php.ini file to the location of you browscap.ini. You can get one at
Re: How do I check if javascript is enabled in PHP?
Jim wrote:
>
How do I check if javascript is enabled in PHP?
The temptation is to use get_browser() function, but it must be
resisted. get_browser() provides you with information about
what the browser CAN do. It cannot, however, tell you whether
the browser IS ALLOWED to do all it can. For example, many
browsers are capable of supporting JavaScript, but in many,
its support can be disabled.
So it's tricky. You can't do "it in one sitting"; you need to
output something (including some JavaScript), then see how the
client reacts to it. For example, this could be your index.php:
<html>
<head>
<script language="JavaS cript">
window.location =
'http://www.yoursite.co m/index1.php?js=1 &token=<?php
echo time();
?>';
</script>
</head>
<body>
<p>Sorry, your browser does not support JavaScript...</p>
</body>
</html>
In index1.php, you check if $_GET['js'] is indeed 1 and if
$_GET['token'] is reasonably close to server's current time.
You will also need a mechanism to propagate this piece of
information...
Re: How do I check if javascript is enabled in PHP?
Jim wrote:
How do I check if javascript is enabled in PHP?
>
TIA,
>
Jim
>
>
Tim,
Just my two pennies:
Don't use PHP to check for javascript enabled / disabled.
Make your pages function properly without javascript, i.e. don't have
any inline javascript in your page - nothing essential should be done
using javascript.
Then in the pages link in an external javascript file in the header.
In this javascript file use something along the lines of:
window.onload = init;
function init() {
// add any javascript functions to the page using the DOM
}
This way, your users can use your site independently of whether
javascript is enabled or disabled as the javascript is only 'added' if
the user has javascript enabled.
An elegant and user-friendly way to deal with the problem.
Good luck,
Juliette
P.S.: if none of the above makes sense to you, stay away from javascript
in the first place.
Comment