0

I don't understand why every column has good results but the screen column has code inside and not the actual SCREEN SIZE (result of the code).

<?php

@$data = $_SERVER['HTTP_USER_AGENT']."|";       
@$data.= $_SERVER['HTTP_CF_CONNECTING_IP']."|";             
$width = " <script>document.write(screen.width); </script>";
$height = " <script>document.write(screen.height); </script>";

$data.=$width;
$data.=$height;    
$finz = explode("|",$data);    
$ag = $finz[0];    
$ip = $finz[1];    
$sc = $finz[2];     
$query1 = $db->prepare("INSERT INTO `checks` (user,type,ip,screen,agent) values (:user,:type,:ip,:screen,:agent)");     
$query1->execute(array(     
    'user' => $USER['username'],
    'type' => 'Red Flower',
    'ip' => $ip,
    'screen' => $sc,
    'agent' => $ag
    ));         
$row2 = $query->fetch();

?>

Can somebody tell me how to make the code insert the values of the JavaScript output without using POST AJAX/JQuery etc?

1 Answer 1

1

The embedded JavaScript won't be evaluated until your template reaches the client. It's not something the PHP interpreter understands. It's just a string. You have to execute this code in JavaScript and send it back to the server, there's no other way.

You will need to send a request back to the server containing the results of the evaluated JavaScript before performing the query against your database.

I realize this is something you were trying to avoid.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, if you can please tell me, how do I make it? I will love to have the code.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.