Nieuw lid |
|
Ik wil op deze plaats (zie code) document.formulier.action = "lampon"; dit hebben <?socket_write($sock, $msg, strlen($msg));?> maar dit werkt niet. Dus met andere woorden kan ik binnen een javascript functie PHP code aanroepen en hoe?
Dit werkt nog niet goed, is de socket nu wel aanroepbaar binnen het script? thanks.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Remote</title><meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<meta name="generator" content="HAPedit 3.1">
<script language="javascript">
<!--
function lamp(on_off) {
if(on_off == 1)
{
<?php /* Send instructions. */
$msg = 'LAMPON';
socket_write($sock, $msg, strlen($msg))?>;
} else {
<?php
/* Send instructions. */
$msg = 'LAMPOFF';
socket_write($sock, $msg, strlen($msg))?>;
}
}
//-->
</script>
<?php
error_reporting(E_ALL);
/* Allow the script to hang around waiting for connections. */
set_time_limit(0);
/* Turn on implicit output flushing so we see what we're getting
* as it comes in. */
ob_implicit_flush();
$address = '78.53.145.34';
$port = 6000;
if (($sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) < 0) {
echo "socket_create() failed: reason: " . socket_strerror($sock) . "\n";
}
if (($ret = socket_connect($sock, $address, $port)) < 0) {
echo "socket_bind() failed: reason: " . socket_strerror($ret) . "\n";
}
?>
</head>
<body bgcolor="#FFFFFF">
<center>
<form method="post" name="formulier">
<input type="button" value="LampOn" onclick="lamp(1)">
<input type="button" value="LampOff" onclick="lamp(0)">
</form>
Lamp is uit
<BR><BR>
</CENTER>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Remote</title><meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="generator" content="HAPedit 3.1"> <script language="javascript"> <!-- function lamp(on_off) { if(on_off == 1) { <?php /* Send instructions. */ $msg = 'LAMPON'; } else { <?php /* Send instructions. */ $msg = 'LAMPOFF'; } } //--> </script> <?php /* Allow the script to hang around waiting for connections. */ /* Turn on implicit output flushing so we see what we're getting * as it comes in. */ $address = '78.53.145.34'; $port = 6000; } } ?> </head> <body bgcolor="#FFFFFF"> <center> <form method="post" name="formulier"> <input type="button" value="LampOn" onclick="lamp(1)"> <input type="button" value="LampOff" onclick="lamp(0)"> </form> Lamp is uit <BR><BR> </CENTER> </body> </html>
|