Jul 25, 2008

How To Put Ina Php Var The Screen Width?

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

How To Put Ina Php Var The Screen Width?

kservice
Hello, i need tu put in $width (a php variable), the screen width of the client, and then do some arithmetics operations with it,

I did this :

CODE

$width = " <script>document.write(screen.width); </script>";

I tested if $width get the value, with this:

echo $width;

And, is ok, but when i multiply $width with any value, I got $width = 0;

example;

My Screen is at 1024 by 768 so:

$width = "<script>document.write(screen.width); </script>";
echo $width; ---------------> 1024

$width = $width * 2;
echo $width; ------------------> 0


Please, Can someone tell me why? and is there a manner to do this!!

Thank's

kservice

Notice from Johnny:
Added code tags.

 

 

 


Reply

electriic ink
One possible solution seems simple

CODE

$width = $width + $width;


and for $width * 3 do

CODE

$width = $width + $width + $width;

Reply

truefusion
Welp, i can tell you why it doesnt work the way you want it to. Reason being, it's impossible to multiply <script>document.write(screen.width); </script> by any number. $width has to equal an integer in order for it to be multiplied, or whatever.

Reply

rvalkass
truefusion is right. The variable $width is not holding a number but is holding a text string. PHP cannot multiply a text string by two, so it returns 0.

After a short time searching on the web I have cobbled together a system that could work, although I have had no time to try it.

Create an HTML page with the following code in it:
CODE

<html>
<head>
</head>
<body>
<script>
window.location="page.php?height="+screen.height+"&width="+screen.width;
</script>
</body>
</html>


Then on the page called page.php (feel free to change it in the script above):
CODE

<?php
$height = $_GET['height'];
$width = $_GET['width'];

//Now the rest of your page...


In page.php the variables should now hold the screen resolution. If you want to check then just echo those variables and see what you get.

Good luck

 

 

 


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : ina php var screen width


    Looking for put, ina, php, var, screen, width

Searching Video's for put, ina, php, var, screen, width
advertisement



How To Put Ina Php Var The Screen Width?



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE