I have a raspberry pi which opens up a webpage on boot. This page loads includes a php page that listens on udp port for input. When the input is received I want another page to load, but I'm having trouble doing this.
Here's index.html
<html style="background-color:#0085b3;">
<body>
<img src="bg.jpg"/>
<div id="content"></div>
</body>
<script src="scripts/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#content").load("udp.php");
});
</script>
</html>
and udp.php
<?php
session_start();
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($socket, '10.10.10.25', 5000);
$from = '';
$port = 0;
socket_recvfrom($socket, $buf, 12, 0, $from, $port);
$buf = preg_replace('/\s+/', '', $buf);
$conn = null;
socket_close($socket);
die("<script>location.href = 'http://10.10.10.20/main.php'</script>");
?>
What happens is that the die function is echoed on the raspberry and the browser doesn't load the main.php webpage
I tried using a single php page to display the image and then listen to the input, but the php code is run at once and displays the html only after receiving some input.
index.php
<?php
echo '<html style="background-color:#0085b3;">';
echo '<body>';
echo '<img src="bg.jpg"/>';
echo '</body>';
echo '</html>';
session_start();
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_bind($socket, '10.10.10.25', 5000);
$from = '';
$port = 0;
socket_recvfrom($socket, $buf, 12, 0, $from, $port);
$buf = preg_replace('/\s+/', '', $buf);
$conn = null;
socket_close($socket);
die("<script>location.href = 'http://localhost/plc/main.php'</script>");
?>
header(location: <URL>); die();?