By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,763 Members | 1,609 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,763 IT Pros & Developers. It's quick & easy.

Servers side JavaScript detection in PHP4

P: n/a
Dear readers,

Is there somewhere, maybe $_SESSION vars?, where my PHP knows that
JavaScript is enabled on the clients webbrowser.
I uses some JavaScript but would like to add workaround in case the browser
doesn't. Suggestions would be appreceated.

Tia Jean.
Aug 5 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Jean Pion wrote:
Dear readers,

Is there somewhere, maybe $_SESSION vars?, where my PHP knows that
JavaScript is enabled on the clients webbrowser.
I uses some JavaScript but would like to add workaround in case the
browser doesn't. Suggestions would be appreceated.

Tia Jean.


Hi,

You cannot get that information from SESSION vars.
SESSION vars ONLY contains information you put into it.
Also the POST or GET will not help.

You can easily check that in another way.
Try something like this:

[on the startpage where you want to detect Javascript]

<form action="jscheck.php" name="jscheckform" method="post">
<input type="hidden" name="jsenabled" value="N">
<input type="submit" value="continue">
</form>
<script type="text/javascript">
document.forms.jscheckform.jsenabled.value="Y";
</script>

Now on the page jscheck.php you just retrieve the value of jsenabled:

$jsenabled=$_POST["jsenabled"];
// and maybe store it in a session for futher reference
$_SESSION["jsenabled"] = $jsenabled;
Hope that helps.

Regards,
Erwin Moller

Aug 5 '05 #2

P: n/a
On 2005-08-05, Jean Pion <je*******@hotmail.com> wrote:
Is there somewhere, maybe $_SESSION vars?, where my PHP knows that
JavaScript is enabled on the clients webbrowser.
That has been already answerd by GM
I uses some JavaScript but would like to add workaround in case the browser
doesn't. Suggestions would be appreceated.


I think it's easier to write scripts that work without JavaScript. And
then add whatever JS.. This gives you the advantage you don't have to
think about workarounds (Simplest solution is to disable JavaScript).

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
Aug 5 '05 #3

P: n/a
"Erwin Moller"
<si******************************************@spam yourself.com> schreef in
bericht news:42***********************@news.xs4all.nl...
Jean Pion wrote:
Dear readers,

Is there somewhere, maybe $_SESSION vars?, where my PHP knows that
JavaScript is enabled on the clients webbrowser.
I uses some JavaScript but would like to add workaround in case the
browser doesn't. Suggestions would be appreceated.

Tia Jean.


Hi,

You cannot get that information from SESSION vars.
SESSION vars ONLY contains information you put into it.
Also the POST or GET will not help.

You can easily check that in another way.
Try something like this:

[on the startpage where you want to detect Javascript]

<form action="jscheck.php" name="jscheckform" method="post">
<input type="hidden" name="jsenabled" value="N">
<input type="submit" value="continue">
</form>
<script type="text/javascript">
document.forms.jscheckform.jsenabled.value="Y";
</script>

Now on the page jscheck.php you just retrieve the value of jsenabled:

$jsenabled=$_POST["jsenabled"];
// and maybe store it in a session for futher reference
$_SESSION["jsenabled"] = $jsenabled;
Hope that helps.


Thanks Erwin,
that sounds fine,
Jean.

Aug 5 '05 #4

P: n/a
"Tim Van Wassenhove" <ti***@users.sourceforge.net> schreef in bericht
news:dc**********@ikaria.belnet.be...
On 2005-08-05, Jean Pion <je*******@hotmail.com> wrote:
Is there somewhere, maybe $_SESSION vars?, where my PHP knows that
JavaScript is enabled on the clients webbrowser.
That has been already answerd by GM


Well I was not aware of this, sorry...
And, - risking to sound even more stupid -, who or what might be GM.
And where can I find the answer.
I uses some JavaScript but would like to add workaround in case the
browser
doesn't. Suggestions would be appreceated.


I think it's easier to write scripts that work without JavaScript. And
then add whatever JS.. This gives you the advantage you don't have to
think about workarounds (Simplest solution is to disable JavaScript).


You are probably right, but I inherited a site with js.

Jean.
Aug 5 '05 #5

P: n/a
Jean Pion wrote:
Is there somewhere, maybe $_SESSION vars?, where my PHP knows that
JavaScript is enabled on the clients webbrowser.
I uses some JavaScript but would like to add workaround in case the browser
doesn't. Suggestions would be appreceated.


After reading the subject, I actually thought this was going to be about
server side javascript... (Which does exist to you nay-sayers.)

One quick solution that I have done before for detecting javascript on a
client is in the document have something like:

<?php
if(!isset($_GET['js']) && !isset($_SESSION['js'])){
$js=<<< eos
<script type="text/javascript">
window.location.href='{$_SERVER['REQUEST_URI']}?js=1';
</script>
eos;
}else{
$_SESSION['js']=1;
$js='';
}
?>
<html>
<head>
<title>Javascript test</title>
<?php echo $js ?>
</head>
<body>
Javascript has <?php if(!empty($js)){ echo '<b>not</b>'; } ?> been
detected on the client.
</body>
</html>

Of course, if the REQUEST_URI already contains a query string, you'd
want to append the js var instead of how I have it above, but it
illustrates the method anyway.

--
Justin Koivisto, ZCE - ju****@koivi.com
http://koivi.com
Aug 5 '05 #6

P: n/a
"Erwin Moller"
<si******************************************@spam yourself.com> schreef in
bericht news:42***********************@news.xs4all.nl...
Jean Pion wrote:
Dear readers,

Is there somewhere, maybe $_SESSION vars?, where my PHP knows that
JavaScript is enabled on the clients webbrowser.
I uses some JavaScript but would like to add workaround in case the
browser doesn't. Suggestions would be appreceated.

Tia Jean.


Hi,

You cannot get that information from SESSION vars.
SESSION vars ONLY contains information you put into it.
Also the POST or GET will not help.

You can easily check that in another way.
Try something like this:

[on the startpage where you want to detect Javascript]

<form action="jscheck.php" name="jscheckform" method="post">
<input type="hidden" name="jsenabled" value="N">
<input type="submit" value="continue">
</form>
<script type="text/javascript">
document.forms.jscheckform.jsenabled.value="Y";
</script>

Now on the page jscheck.php you just retrieve the value of jsenabled:

$jsenabled=$_POST["jsenabled"];
// and maybe store it in a session for futher reference
$_SESSION["jsenabled"] = $jsenabled;

There is a drawback to this, being that a button is visible, and one should
click it.
So after some browsing I found the following suggestion to solve this:
<form action="some_url" name="jscheckform" method="post">
<input type="hidden" name="jsenabled" value="N">
</form>

<script type="text/javascript">
<!--
document.forms.jscheckform.jsenabled.value="Y";
document.forms.jscheckform.submit();
//-->
</script>

So, nothing is visible and no need to press any button.
My problem is what to use for action parameter.
I dont wan't to show another page, can I use the same url?

Another is that I currently don't accept post to this page...

Tia, Jean.
Aug 5 '05 #7

P: n/a
<html>
<head>

<meta http-equiv="refresh"
content="0;url=http://www.somedomain.com/?js=0">

<script language=javascript>
<!--
window.location='http://www.somedomain.com/?js=1';
-->
</script>

<style type="text/css">
a,p {
color: 888888;
}
</style>

</head>
<body>

<p>
If the page doesn't refresh, please

<a href="http://www.somedomain.com/?js=0">
Click Here
</a>

</body>
</html>

Aug 5 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.