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

Passing a Java variable to local PHP script.

P: n/a
Hello everyone,

I've spent quite some time now, looking for some information on how to
get this done, sadly none has helped me much, though.
I have a bit of java scrpt on a webpage (.php) to aquire the screen
resolution of the visiting user. Now I need to pass the java variable
to another variable on the same document.

I have a feeling, this will not be easy - as java is client- and php
server-sided. Now, if my assumption is corect, then it will be
neccessary to generate the page via .php on the webserver and send it
to the browser. Once loaded, java will be executed to aquire the used
screen resolution. These values (height/width) will have to be
returned to the server, prob. via post. The server will now have to
acknowledge the presence of these values and regenerate the webpage
once more, this time using the provided values.

I hope I've got it so far. Problem is - I don't have a clue about java
and only basics in php. Please help me get this accomplished, abd
don't forget: I'm not java savy.

kind regards,

Andy R.
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Andy R. wrote:
Hello everyone,

I've spent quite some time now, looking for some information on how to
get this done, sadly none has helped me much, though.
I have a bit of java scrpt on a webpage (.php) to aquire the screen
resolution of the visiting user. Now I need to pass the java variable
to another variable on the same document.


Firstly JavaScript != Java, they just share a name.

What you need to do is send a 'detect' page if you don't already know
the screensize. This will redirect to the original page passing the
screen size.

Create a file called screensize.php.
<?php
if ($_GET['screensize']) {
$_SESSION['screensize'] = $_GET['screensize'];
}

if (!$_SESSION['screensize']) { ?>
<html>
<head>
<script language=javascript>
window.location.href="<?=$PHP_SELF?>?screensize=" +
screen.width + "x" + screen.height;
</script>
</head>
<body>
Checking screen size
</body>
</html>
<?php exit();
} ?>

Then just include('screensize.php'); at the top of your pages. All of
them will have $_SESSION['screensize'] set for you.

NOTE: the user may not have their browser full screen.
Jul 17 '05 #2

P: n/a
"Andy R." <No*******@mailinator.com> wrote in message
news:93**************************@posting.google.c om...
Hello everyone,

I've spent quite some time now, looking for some information on how to
get this done, sadly none has helped me much, though.
I have a bit of java scrpt on a webpage (.php) to aquire the screen
resolution of the visiting user. Now I need to pass the java variable
to another variable on the same document.

I have a feeling, this will not be easy - as java is client- and php
server-sided. Now, if my assumption is corect, then it will be
neccessary to generate the page via .php on the webserver and send it
to the browser. Once loaded, java will be executed to aquire the used
screen resolution. These values (height/width) will have to be
returned to the server, prob. via post. The server will now have to
acknowledge the presence of these values and regenerate the webpage
once more, this time using the provided values.

I hope I've got it so far. Problem is - I don't have a clue about java
and only basics in php. Please help me get this accomplished, abd
don't forget: I'm not java savy.

kind regards,

Andy R.


Don't reload the page, load a blank image,

<IMG SRC="blank.gif" NAME="imgscreensize">

<SCRIPT>
// do you stuff here
imgtime.src = "screensize.php?w=" + varWidth + "&h=" + varHeight;
</SCRIPT>
then have screensize.php do something like this
<?php

// log your stuff here

header("Content-type: image/gif");
readfile("blank.gif");
?>
--
Mike Bradley
http://www.gzentools.com -- free online php tools
Jul 17 '05 #3

P: n/a

Uzytkownik "Kevin Thorpe" <ke***@pricetrak.com> napisal w wiadomosci
news:40***********************@news.easynet.co.uk. ..
Create a file called screensize.php.
<?php
if ($_GET['screensize']) {
$_SESSION['screensize'] = $_GET['screensize'];
}

if (!$_SESSION['screensize']) { ?>
<html>
<head>
<script language=javascript>
window.location.href="<?=$PHP_SELF?>?screensize=" +
screen.width + "x" + screen.height;
</script>
</head>
<body>
Checking screen size
</body>
</html>
<?php exit();
} ?>


Consider using window.location.replace(url) instead, so that the back button
behaves more reasonably.

Jul 17 '05 #4

P: n/a
Hi Andy,

Assuming you only need to adjust the size of some html elements to the
screen size, you could do resizing entirely in javascript by something like:

<HTML><HEAD></HEAD>
<BODY onResize="scaleContent()>
<script>
function scaleContent() {

getElement('itemTableDiv').style.height=(window.do cument.body.clientHeight)-179;
getElement('itemTableDiv').style.width=(window.doc ument.body.clientWidth)-130;
}

function getElement( elementId)
{
var element;

if (document.all) {
element = document.all[elementId];
}
else if (document.getElementById) {
element = document.getElementById(elementId);
}
else element = -1;

return element;
}
</script>

<div id=itemTableDiv style='height: 300px; width: 600px; overflow:
auto;' valign='top'>
<?php printItemTablePart() ?>
</div>
<script> scaleContent(); </script>
</BODY>
</HTML>

This resizes a DIV according to screen size minus (130, 179). You can
fill in different values to make it larger or smaller, or print the
proper values from php. It works in recent versions of both IE and
Mozilla, (not in Nescape 4.x). Of course you need to write the
printItemTablePart() function in php to produce the content of the div,
or just print it some other way from php.

This javascript will probably work on other types of html elements too,
as long as you give each one a different id, and as long as the scaling
is not making them too small for their own elements to fit in. Be aware
that the second script must be AFTER the definition of the elements that
are resized and after the functions that are called.

Greetings,

Henk Verhoeven,
www.phpPeanuts.org
Andy R. wrote:
Hello everyone,

I've spent quite some time now, looking for some information on how to
get this done, sadly none has helped me much, though.
I have a bit of java scrpt on a webpage (.php) to aquire the screen
resolution of the visiting user. Now I need to pass the java variable
to another variable on the same document.

I have a feeling, this will not be easy - as java is client- and php
server-sided. Now, if my assumption is corect, then it will be
neccessary to generate the page via .php on the webserver and send it
to the browser. Once loaded, java will be executed to aquire the used
screen resolution. These values (height/width) will have to be
returned to the server, prob. via post. The server will now have to
acknowledge the presence of these values and regenerate the webpage
once more, this time using the provided values.

I hope I've got it so far. Problem is - I don't have a clue about java
and only basics in php. Please help me get this accomplished, abd
don't forget: I'm not java savy.

kind regards,

Andy R.


Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.