A part of my project need to get datas from an ESP8266 with php script. I tested this script and i don't know why i can get the datas in an iframe element and nothing with file_get_content function. In iframe element my browser displayes "Hello my friend!" as wanted:

The ESP8266 server mode at address, part of code:

String webpage = "<div id='div1'>Hello</div>";
webpage += "<div id='div2'>my</div>";
webpage += "<div id='div3'>friend!</div>";

String cipSend = "AT+CIPSEND=";
cipSend += 0;
cipSend += ",";
cipSend +=webpage.length();
cipSend +="\r\n";

sendData("AT+CIPCLOSE=0\r\n", 100, DEBUG);

The php script:

    <iframe src=",0,0,"></iframe>


 $lines_string = file_get_contents($url);
 echo htmlspecialchars($lines_string);


If i replace the url by:


It works with php script,so what is the issue with the ESP8266 ?

  • Where does the PHP run? I think your PHP is running on a remote server, while the ESP is on a local network (behind a NAT), with a local IP address. The remote server can't access your local network, while you browser can. – Gerben Nov 20 '18 at 16:35
  • Php script is running on php home server Linux machine. I can send all i want to the ESP8266 by wifi. – Teddol Nov 20 '18 at 16:38
  • Is your home server on the same network (/subnet)? Can you curl/gwet the url from your home server? – Gerben Nov 20 '18 at 16:42
  • No home network. Just php server (localhost) and ESP8266 as access point. – Teddol Nov 20 '18 at 17:13

To process the request by php, you must send valid HTTP response. The browser tolerates too much.

String webpage = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n";
webpage += "<div id='div1'>Hello</div>";
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.