Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 10th, 2006, 12:37 PM
Authorized User
 
Join Date: Jun 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Change php Variable with javascript

Hi
I created a webpage that has a lot of javascript on it. what I want to do is when javascript is disabled on browser, change phpvar to 0 so php do not include any java files.
Here what I did:

/*--------Code-----------*/
<? php $js=0; ?>

<script language="javascript">
var jsTest = navigator.javaEnabled();
if(jsTest)
  js = 1;
</script>

<?
$js = '<script language="javascript">document.write(js);</script>';

if($js == 1)
  include("page.php");
else
  echo "Error";
?>

But either way java disabled or not it still includes page.php.
I tried to output the $js -> with java enabled is 1, otherwise it nothing.
My question is whats wrong with that code?


Thanks
Best Regards
Mani H.

 
Old October 27th, 2006, 09:43 AM
Registered User
 
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to x86_Demon
Default

Hi,
JavaScript work's on client side but PHP - on server!

PHP only generate HTML code that you see in browser, and do some server work.
When you write <script>js=1;</script> browser set JS variable on client side.

Try to do:
<?php
if(!$_SESSION['jsEnabled']) {
echo '<iframe name="frame_n" src="about:blank"></iframe>
<script>
window.parent.frame_n.document.location.href="set_ js_enabled.php";
</script>
';
}
?>

In set_js_enabled.php :
<?php
session_name(<name>);
session_start();
$_SESSION['jsEnabled']=1;
?>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Detect Variable change in C# tusharkale C# 1 July 8th, 2008 02:14 AM
storing Javascript variable to ASP variable rupen Classic ASP Basics 5 April 10th, 2007 07:06 AM
assign javascript variable to asp variable manjunath_c_k Classic ASP Basics 1 September 14th, 2006 07:35 AM
Passing javascript variable to html or php ashraf_gawdat Javascript How-To 3 July 12th, 2006 02:48 PM
passing php variable to javascript and vice versa onmcv Beginning PHP 0 March 24th, 2005 01:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.