save resolution into db

kaits

Mitglied
$reso = "<script language=\"Javascript\">document.write(screen.width +' x '+ screen.height +'|'+ screen.colorDepth)</script>";

result in my computer if i echo it: 1280 x 1024|16

but how to insert this variable into database without showing it to the user?
i insert just as variable and it saves only the full javascript code :(
 
You might try to use a "blind" frame (height="0") and load a form into this frame. Simply fill the input fields with the screen resolution and send the content to a php script which stores it into the database.

No idea if this works. But I guess it should do... ;)
 
I made an iframe (hright and width = 0) and source file:
PHP:
<?
$reso = "<script language=\"Javascript\">document.write(screen.width +' x '+ screen.height +'|'+ screen.colorDepth)</script>";
?>

But how do I get the variable? Just echo $reso; doesn't work :(
The file, whitch saves information into database, is also included (at the end of the file).
 
<?
$reso = "<script language=\"Javascript\">document.write(screen.width +' x '+ screen.height +'|'+ screen.colorDepth)</script>";
echo "<textarea>$reso</textarea>";
echo "<a href='javascript.document.form.submit()'>
?>
 
I have index.php
There I include:
funcs.php includes all functions
frame.php includes the variable $reso
save.php that saves all variables into MySQL database

index.php includes an iframe code whitch sourcefile is frame.php

So, the $reso is in frame.php and if I now write into index.php echo $reso; then nothing happens :(
And the same in mysql.php: "'.addslashes($reso).'" saves nothing, just an empty field :( :(

How to run the javascript without showing the screen size to the guest and put the screen size into variable and insert the screen size into database??
 
Code:
<script language="JavaScript">
<!--
function sendResolution()
{
    var height = screen.availheight;
    var width = screen.availwidth;
    document.forms(0).fields(0).value = height;
    document.forms(0).fields(1).value = width;
    document.forms(0).submit();
}
//-->
</script>

<body onLoad="sendResolution();">
<form method="post" action="yourfile.php">
  <input type="text" name="height" value="">
  <input type="text" name="width" value="">
</form>
</body>
This should send the screen information to a php file so you can store it in a database.
Put this code into your invisible frame.
 
I don't know, that javascript doesn't work too :( :(
PHP:
$a = "<script language=\"Javascript\">document.write(screen.width)</script>";
$b = "<script language=\"Javascript\">document.write(screen.height)</script>";
$c = "<script language=\"Javascript\">document.write(screen.colorDepth)</script>";
$d = $a.'|'.$b.'|'.$c;
echo $d;
mysql_query('INSERT INTO statistika (id,resojavarvid) VALUES (0,"'.addslashes($d).'")');

See, I echo it and it shows 1280|1024|16 and after that I insert it into MySQL database but it saves the full code of $a, $b and $c like that:
<script language=\"Javascript\">document.write(screen.width)</script><script language=\"Javascript\">document.write(screen.colorDepth)</script><script language=\"Javascript\">document.write(screen.colorDepth)</script>

:( :( :( :(
 
Erm... remember that javascript is parsed by the browser (client) while php is parsed by the server itself. Surely there is no chance to figure out the clients resolution using php only.
PHP only echoes the javascript to the client and it will be interpreted after the PHP script has run.
 
Original geschrieben von asphyxia
Code:
<script language="JavaScript">
<!--
function sendResolution()
{
    var height = screen.availheight;
    var width = screen.availwidth;
    document.forms(0).fields(0).value = height;
    document.forms(0).fields(1).value = width;
    document.forms(0).submit();
}
//-->
</script>

<body onLoad="sendResolution();">
<form method="post" action="yourfile.php">
  <input type="text" name="height" value="">
  <input type="text" name="width" value="">
</form>
</body>

This should send the screen information to a php file so you can store it in a database.
Put this code into your invisible frame.

it doesn't work, a javascript error somewhere :(
 
Arghs, sorry... kick my ass!
Define the index of an array in javascript with [] - not with normal brackets. I'm coding too much Visual Basic. :rolleyes:
I hope that's been the only syntax error in that script.
 
Zurück