I am a beginner / hobbyists programmer. I am working on a webcam application that also has some gpio pins by piecing together code I have found online. I have an img src tag in an index.php file that needs to change depending on whether I access the page from within my lan or externally.
I found the following information on another forum that works if I manually change the img src tag to be an internal or external ip depending on if I am on my LAN or not, but I would like to be able to access the page from either one without needing to manually change the index.php file.
Options I found on raspberry pi forum: Change the tag to use your external IP. If this breaks the internal network, you can either use a separate page for internal vs external, or you can write a script to determine if the http client is coming from an internal or external IP, and change the tag accordingly.
Could someone show me how to implement an alternate index page or script that would change the img src tag depending on if the client is on an external or internal network?
Here is the code for the index page with img src tag:
<!DOCTYPE html>
!--TheFreeElectron 2015, http://www.instructables.com/member/TheFreeElectron/ -->
<html>
<head>
<meta charset="utf-8" />
<title>Raspberry Pi Gpio</title>
</head>
<body style="background-color: black;">
<center>
<img src="http://192.168.0.34:8080/stream/video.mjpeg">
</center>
<!-- On/Off button's picture -->
<?php
$val_array = array(0,0,0,0,0,0,0,0);
//this php script generate the first page in function of the file
for ( $i= 0; $i<8; $i++) {
//set the pin's mode to output and read them
system("gpio mode ".$i." out");
exec ("gpio read ".$i, $val_array[$i], $return );
}
//for loop to read the value
$i =0;
for ($i = 0; $i < 8; $i++) {
//if off
if ($val_array[$i][0] == 0 ) {
echo ("<img id='button_".$i."' src='data/img/red/red_".$i.".jpg' onclick='change_pin (".$i.");'/>");
}
//if on
if ($val_array[$i][0] == 1 ) {
echo ("<img id='button_".$i."' src='data/img/green/green_".$i.".jpg' onclick='change_pin (".$i.");'/>");
}
}
?>
<!-- javascript -->
<script src="script.js"></script>
</body>
</html>
Thanks