Forum Moderators: coopster

Message Too Old, No Replies

PHP Pass Var to JS for if then

passing var to js for IF then

         

zour1el

1:17 am on Oct 2, 2007 (gmt 0)

10+ Year Member



im trying to figure out how to pass a varible from a PHP page to a JS script for an If then....

the run down ..... i was trying to figure out how 2 sets of ppl can go to a webpage and based off there IP address <192 = usersetA and 32 =usersetb> goto the same webpage but a different set of CSS load.

the code
HTML page

<html>
<script type="text/javascript" src="ip.php"></script>
<body>
<script>
var confirmJS=<?php echo ($rest);?>;

if (confirmJS!=1)
{
document.writeln("correct");
}
else
{
document.writeln("hmmmmmmm");
}
document.writeln("<br>" + "The divisor is " + divisor);
// end hiding code -->
</script>

</body>
</html>

the PHP page

<?
//"ip.php" example- display user IP address on any page
Header("content-type: application/x-javascript");
$serverIP=$_SERVER['REMOTE_ADDR'];
$rest = substr($serverIP,0, 1);

echo "document.write(\"Your IP address is: <b>" . $rest . "</b>\")";

right now it doesnt look like the php is passing the var over everything comes up as a true statement.....

NEWBIE that is lost....

Tastatura

3:16 am on Oct 2, 2007 (gmt 0)

10+ Year Member



Do you really need JS for this? If I correctly understand what you want to do, you can easily accomplish it via PHP alone.

zour1el

3:20 am on Oct 2, 2007 (gmt 0)

10+ Year Member



nope..

i will say all changes to webpages will have to happen around 4K times :)

PHP_Chimp

5:43 pm on Oct 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unless you want to change the CSS without having to reload the page then stick to just PHP. If you want to enable CSS changing without reloading the page then you will have to have all of the CSS cached then use your JS to activate 1 of them...that seems like a huge waste of server power.

If you are reloading the page with each CSS request then just stick to PHP as this will be parsed each time the page is reloaded anyway.