Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass PHP variable to Javascript?

Status
Not open for further replies.

bstonehill

IS-IT--Management
Feb 9, 2007
9
US
I need to open a popup to the current router ip address which is extracted through php and stored in the array $gateway[1]. I can open a popup to a specific location but I do not even get a popup at all if I try to use the PHP variable as the location. Here is where I am at:



<?php

$ipconfig = shell_exec('ipconfig /all');
$explode = explode(':', $ipconfig);
$gateway = explode(" ", $explode[14]);

echo('<script type="text/javascript">);
echo("window.open(\"$gateway[1]\");");
echo('</script>');
 
You're probably fighting getting all the interior quotes escaped right. Try the heredoc syntax for printing this kind of stuff:

Code:
<?php 
$gateway = array ('foo', 'bar', 'baz');

echo <<< EOL
window.open("$gateway[1]");
EOL;
?>

Outputs:

[tt]window.open("bar");[/tt]


Want the best answers? Ask the best questions! TANSTAAFL!
 
That was actually part of an IF statement. Now I get an error...

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\Abyss Web Server\htdocs\102.53.94.50\htdocs\webpass.php on line 53

which is this line:
If($_POST['password'] == Null) {}

The full php segment is:

If($_POST['password'] == 'sentrytech') {

echo <<< EOL
window.open("$router");
EOL;

}

Else {
If($_POST['password'] == Null) {}
Else {
echo('<h3>Invalid Password</h3>');
}
}

Do I still have to start a script with this method? i.e. echo "<script type='text/javascript'>";

Also would be curious to know what the "echo <<< EOL" actually does.

Thanks a lot for the help!
 
You need to read up on people's solutions and not implement them blindly. The PHP online manual entry on heredoc has the warning:

It is very important to note that the line with the closing identifier contains no other characters, except possibly a semicolon (;). That means especially that the identifier may not be indented, and there may not be any spaces or tabs after or before the semicolon.

(Emphasis from the manual)


Want the best answers? Ask the best questions! TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top