Setting A Variable In Php

how do I get php to set it right?

Page 1 of 1

7 Replies - 2203 Views - Last Post: 08 July 2003 - 11:35 PM Rate Topic: -----

#1 Unimagined  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 95
  • Joined: 06-September 02

Setting A Variable In Php

Post icon  Posted 06 July 2003 - 01:35 AM

I'm trying to get php to have a variable that is a number. I'm using javascript to get the number for php, but instead of the variable being set to the number it's getting set to the javascript code.
Here's the code I'm using:

<?php
$width = ("<script><!--
document.writeln(screen.width);
// -->
</script>");
print ("Screen width is $width.\n");
?>

This is what gets published as the html source for the page:

Screen width is <script><!--
document.writeln(screen.width);
// -->
</script>.

I'd like it to set the $width variable to the number that the javascript gets.
Say the value that the javascript got was 1024. I'd like the php variable $width to be set to the value, not the actual javascript itself.
so the html source would look like this:

Screen width is 1024.

Please help.

Is This A Good Question/Topic? 0
  • +

Replies To: Setting A Variable In Php

#2 Dr. Tim  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 993
  • Joined: 20-March 02

Re: Setting A Variable In Php

Posted 06 July 2003 - 07:21 AM

The javascript is rendered at the users end, so you can't use it in your PHP really until after the script is ran. (If I'm right)
Was This Post Helpful? 0
  • +
  • -

#3 klewlis  Icon User is offline

  • cur tu me vexas?

Reputation: 8
  • View blog
  • Posts: 1,723
  • Joined: 09-November 01

Re: Setting A Variable In Php

Posted 06 July 2003 - 09:46 AM

the javascript is interpreted last, after the php is interpreted, so you can't do it that way.

however, if it's really as simple as your example code, why don't you just print it out with javascript and skip that bit of php altogether?
Was This Post Helpful? 0
  • +
  • -

#4 Unimagined  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 95
  • Joined: 06-September 02

Re: Setting A Variable In Php

Posted 06 July 2003 - 10:32 AM

I forgot about that. I would skip it but I need the screen width and heidth values for a php script I'm putting together to set table width and heidth values. Does anyone know how to use php to get the users screen size?

This post has been edited by Unimagined: 06 July 2003 - 12:41 PM

Was This Post Helpful? 0
  • +
  • -

#5 Unimagined  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 95
  • Joined: 06-September 02

Re: Setting A Variable In Php

Posted 06 July 2003 - 12:40 PM

How can I use this script to redirect the user to a php page, but pass the width and height on like this:

http:www.thewebsite.com/size.php?height=' +
screen.height + '\&width=' + screen.width + '"

How can I pass the values using this javascript code:

<script language="javascript">
<!--

location.replace("http://www.somewebsite.com/size.php");

-->
</script>

I'd like to append the width and height values, pass them, to that php script the page is being redirected to. Does anyone know how to do that?
Was This Post Helpful? 0
  • +
  • -

#6 gneato  Icon User is offline

  • <title>Untitled Document</title>

Reputation: 0
  • View blog
  • Posts: 1,311
  • Joined: 03-September 01

Re: Setting A Variable In Php

Posted 06 July 2003 - 01:03 PM

<script type="text/javascript">
<!--
window.location.href='http:www.thewebsite.com/size.php?height=' + screen.height + '&width=' + screen.width;
// -->
</script>
Was This Post Helpful? 0
  • +
  • -

#7 Unimagined  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 95
  • Joined: 06-September 02

Re: Setting A Variable In Php

Posted 08 July 2003 - 09:24 PM

I made a html file with this in it:

<script type="text/javascript">
<!--
window.location.href='http:www.thewebsite.com/size.php?h=' + screen.height + '&w=' + screen.width;
// -->
</script>

I put that code in an html file, then I made a php script with this in it:

<?php
print ("Screen width is $w.\n<br>\n");
print ("Screen width is $h.\n");
$TblWdth = ($w - 600);
print ("<table width=\"$TblWdth\" height=\"100\" border=\"1\">
<tr>
<td>
</td>
</tr>
</table>");
?>

It won't work. I'm trying to get the first page to automatically redirect the user to the php page, but have the first page pass the width and height variables from the javascript on to the php page.
Was This Post Helpful? 0
  • +
  • -

#8 Unimagined  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 95
  • Joined: 06-September 02

Re: Setting A Variable In Php

Posted 08 July 2003 - 11:35 PM

I got it to work with this:

<script type="text/javascript">
<!--
location.replace("http://www.thewebsite.com/size.php?h=" + screen.height + "&w=" + screen.width);
// -->
</script>

Thank you for your help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1