Arduino webserver and PHP?

Hello i have a question well some mixed feeling on this subject i have seen online But this i from a programming point of view. But can a Arduino Webserver host a PHP page and it's content that is within PHP? Granted the arduino it's self can not do this but what about Using a SD card to have the PHP page on it? Would that be possible? I'm just wondering from a programming point of view if it is possible?

Okay let me try to rephrase a few of my words just in case I have seen some mixed feeling online some say it can be done or can't be done and for my self I'm just wondering.

The purpose of PHP (or Ruby or Python) for web applications is so that the webserver can do complex things. The server has to be able to run the PHP code. And (in case of doubt) the PHP code is not sent to the browser.

...R

Hello Robin Understandable. But what about Simple php page just echoing things for display like text or pictures and whatnot Something simple? I know html can do all this but i do have some php pages that have some of the same things that is on my html pages But also they have some javascript code as well. Like i have a form on one of my pages got css and javascript on it.

You would have to have a PHP interpreter running ON the Arduino. Don't know if such a thing exists., but if it does, I'd bet it would be a severely restricted sub-set of the full PHP functionality...

Regards, Ray L.

Hello RayLivingston thank you. But i was wondering if the php page would be on the sd card not the coding it's self be in the arduino.

That would be up to the PHP implementation, but I can't see how it could realistically be executed directly from the SD card....

Regards, Ray L.

Hello thank you. That part i will have to look in that is a very good question.

Web pages are essentially text files which can be served from an arduino. If the web page is to do something, the page needs to have links to servers that can actually execute that is requested.

Thank you Zoomkat

josephchrzempiec: But i was wondering if the php page would be on the sd card not the coding it's self be in the arduino.

When you create a web page that includes PHP code as well as HTML the server must execute the PHP code to create an all-HTML page before it sends the page to the browser.

An Arduino cannot execute PHP.

If you have a web page with PHP in it have a look at the source code as seen by your browser and you will see that the PHP has disappeared.

...R

Thank you Robin

Hello i have one Question i have a folder in my sd card in there i have a bunch of pictures for test. How can i be able to thought the html webpage view what is in that folder and click on one of them to view it in the webpage? or same thing with a song?

I know you can view the file names in the serial monitor But i would like to view them in the site.

Basic server test code for uploading a picture from the SD card.

//zoomkat 12/26/12
//SD server test code
//open serial monitor to see what the arduino receives
//address will look like http://192.168.1.102:84 when submited
//for use with W5100 based ethernet shields

#include <SD.h>
#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 
  192, 168, 1, 102 }; // ip in lan
byte gateway[] = { 
  192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 
  255, 255, 255, 0 }; //subnet mask
EthernetServer server(84); //server port
String readString; 

//////////////////////

void setup(){

  Serial.begin(9600);

  // disable w5100 while setting up SD
  pinMode(10,OUTPUT);
  digitalWrite(10,HIGH);
  Serial.print("Starting SD..");
  if(!SD.begin(4)) Serial.println("failed");
  else Serial.println("ok");

  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  //delay(2000);
  server.begin();
  Serial.println("Ready");
}

void loop(){
  // Create a client connection
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {
          //store characters to string 
          readString += c; 
          //Serial.print(c);
        } 
        //if HTTP request has ended
        if (c == '\n') {

          ///////////////
          Serial.println(readString); //print to serial monitor for debuging 

            client.println("HTTP/1.1 200 OK"); //send new page
          //client.println("Content-Type: text/html");
          client.println("Content-Type: image/jpeg");
          //client.println("Content-Type: image/gif");
          //client.println("Content-Type: application/x-javascript");
          //client.println("Content-Type: text");

          client.println();

          //File myFile = SD.open("boom.htm");
          File myFile = SD.open("HYPNO.JPG");
          //File myFile = SD.open("BLUEH_SL.GIF");
          //File myFile = SD.open("SERVOSLD.HTM");

          if (myFile) {

            byte clientBuf[64];
            int clientCount = 0;

            while(myFile.available())
            {
              clientBuf[clientCount] = myFile.read();
              clientCount++;

              if(clientCount > 63)
              {
                // Serial.println("Packet");
                client.write(clientBuf,64);
                clientCount = 0;
              }
            }
            //final <64 byte cleanup packet
            if(clientCount > 0) client.write(clientBuf,clientCount);            
            // close the file:
            myFile.close();
          }
          delay(1);
          //stopping client
          client.stop();
          readString="";
        }
      }
    }
  } 
}

Hello Zoomkat thank you for that. From what I'm seeing this line File myFile = SD.open("HYPNO.JPG"); i have to change to my own. so i did File myFile = SD.open("pic.jpg"); and it displayed one of my images. But the thing is how can i display all my images without having to manually put them in?

Or be able to Display them in the html page problem is when i try to display them in the html page they won't display the file names also need to be in the sketch as well.

You can make conditional statements in your server code that determine if "pic.jpg" is in the GET requestlike below, then open "pic.jpg" and send it back. Bottom link is to an old servo slider project with all the files used attached in slider files.zip file. You can look at the web page and see how the files are embedded in the web page.

http://192.168.1.102:84/?pic.jpg

http://forum.arduino.cc/index.php?topic=279849.msg1970392#msg1970392

Hello i know how images are placed but everything is most coded for php I searched a lot of sites that have grab images from a folder and display them but every site so far i went to the coding is in php

This is my sketch for the arduino

#include <SPI.h>
#include <EthernetV2_0.h>
#include <SD.h>

// MAC address from Ethernet shield sticker under board
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177); // IP address, may need to change depending on network
EthernetServer server(8036);  // create a server at port 80

File webFile;

void setup()
{
    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients
    Serial.begin(9600);       // for debugging
    
    // initialize SD card
    Serial.println("Initializing SD card...");
    if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        return;    // init failed
    }
    Serial.println("SUCCESS - SD card initialized.");
    // check for index.htm file
    if (!SD.exists("index.htm")) {
        Serial.println("ERROR - Can't find index.htm file!");
        return;  // can't find index file
    }
    Serial.println("SUCCESS - Found index.htm file.");
}

void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println();
                    // send web page
                    webFile = SD.open("index.htm");        // open web page file
                    if (webFile) {
                        while(webFile.available()) {
                            client.write(webFile.read()); // send web page to client
                        }
                        webFile.close();
                    }
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}

This is my html code

<!DOCTYPE html>
<html>
    <head>
        <title>Arduino SD Card Web Page</title>
    </head>
    <body>
        <h1>Hello from the Arduino SD Card!</h1>
        <p>A web page from the Arduino SD card server.</p>
		

		<img src="464601-97156.png">
    </body>
</html>

I can not display the image but yet the image is on the sd card i can see it.

You might try adding a slash like in the bottom code box. That should relate the file location back to the web page originating IP address.

<img src="464601-97156.png">
<img src="/464601-97156.png">