Because Javascript (usually) client technology and PHP (usually) server technology are used, since HTTP is a "stateless" protocol, variables cannot be directly shared between the two languages.
However, people may use the relationship between variables. One way is to complete the creation of Javascript code using PHP, refresh the browser itself, and return the PHP script through specific variables. The following example exactly shows how to do this-it enables p hp code to capture the screen height and width, which is usually the only possible on the client. Htmlspecialchars () function
<? Php
Echo "<input type = 'ddn' value = '". htmlspecialchars ($ data). "'/> n";
?>
Php url
<? Php
Echo "<a href = '". htmlspecialchars ("/nextpage. php? Stage = 23 & data =".
Urlencode ($ data). "'> n";
?>
<? Php
If (isset ($ _ GET ['width']) AND isset ($ _ GET ['height']) {
// Output the geometry variables
Echo "Screen width is:". $ _ GET ['width']. "<br/> n ";
Echo "Screen height is:". $ _ GET ['height']. "<br/> n ";
} Else {
// Pass the geometry variables
// (Preserve the original query string
// -- Post variables will need to handled differently)
Echo "<script language = 'javascript '> n ";
Echo "location. href =" $ {_ SERVER ['script _ name']}? $ {_ SERVER ['query _ string']}"
. "& Width =" + screen. width + "& height =" + screen. height; n ";
Echo "</script> n ";
Exit ();
}
?>