How to use php file_get_contents with ESP8266

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

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 192.168.4.1 address, part of code:

String webpage = "
Hello
"; webpage += "
my
"; webpage += "
friend!
"; String cipSend = "AT+CIPSEND="; cipSend += 0; cipSend += ","; cipSend +=webpage.length(); cipSend +="\r\n"; sendData(cipSend,1000,DEBUG); sendData(webpage,1000,DEBUG); sendData("AT+CIPCLOSE=0\r\n", 100, DEBUG);

The php script:


    
    

 htmlspecialchars($lines_string);

?>
    

If i replace the url by:

$url=https://arduino.stackexchange.com

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

profilepic.png
manpreet 2 years ago

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 += "
Hello
";

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.