473,396 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Servers side JavaScript detection in PHP4

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
7 4571
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
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
"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
"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
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
"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
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: christian9997 | last post by:
Hi We have started off using a $_GET parameter to keep track of the user's browser: We detect what browser the visitor is using when he first arrives on our website then we do a redirect to...
72
by: Stephen Poley | last post by:
I have quite often (as have probably many of you) come across HTML forms with irritating bits of Javascript attached. The last straw on this particular camel's back was a large form I was asked to...
6
by: John Sheppard | last post by:
Hello there, I am unsure as to where to ask for help about this, so I thought I might try here. Our website works correctly for 99.9% of customers, however we have one set of customers who...
1
by: What-a-Tool | last post by:
I'm playing around in my personal site trying to figure out a way to detect if JavaScript is enabled client side, and get that info back to the server without any manual intervention, or visibility...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
1
by: oreng | last post by:
Hey all, I have some problems detecting whether the client's browser javascript is enabled at the server side. While Request.Browser.JavaScript only check if the browser enable java script (and...
7
by: Bredahl jensen | last post by:
Most of the the solution i have seen was throught javascript. Many thanks in advance JB
4
by: trpost | last post by:
I am looking for a script using javascript to pull browser information including, browser type and version, OS info, plugins (flash, acrobat, media player, etc), java version, etc. that will work...
3
by: Jeremy Chapman | last post by:
Is there any way via server side code to determine if the browser supports javascript?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.