Forum Moderators: open
<script language="JavaScript1.2" type="text/javascript">
<!--
if (screen.width<1024) { document.write("<?php $var = 1;?>");
}
else { document.write("<?php $var = 2;?>");
}
// -->
</script>
What I've found though, is that PHP reads both statements regardless of screen size, and sets $var equal to the last value it finds (in this case, '2').
Is there a way to make this work conditionally?
What you can do, however, is use JavaScript to set a cookie with the information. Then, on subsequent page views you can let PHP read the cookie to retrieve the variable. This cookie will not be available until the second page view.