Code with PHP file will not execute

I hope I can explain my problem well enough for someone to help me.

Problem
One line in a PHP file, within an includes folder on a HTTPS server will not execute (is ignored). If the same PHP file is in an includes folder of a HTTP server, the line will execute.

PHP File
This is a simple PHP file that sends a text message to my cell phone.

Here is the function that contains the problematic code line:

void send_text(int interval, float tank_level){
    
    String current_tank_level = String (tank_level,2);
    
    postData = postVariable + current_tank_level; 

    unsigned long tank_level_currentMillis = millis(); 
      
    if (tank_level_currentMillis - tank_level_previousMillis >= interval) 
      { 
        tank_level_previousMillis = tank_level_currentMillis;
        if (client.connect(server, portNumber))  
            {
              Serial.println("\t ... Connected to Talavera server ....\n");
              client.println("POST /includes/test_text.php HTTP/1.1"); 
              client.println("Host: www.talaveramdwca.org"); 
              client.println( "Content-Type: application/x-www-form-urlencoded" );
              client.print("Content-Length: ");
              client.println(postData.length());
              client.println();
              client.print(postData);
              Serial.println("\n\t\t ... TEXT Sent!\n"); 
            }
            if (client.connected()) {
                client.stop();
             }
      }
  }

The line of code in question is:

 client.println("POST /includes/test_text.php HTTP/1.1"); 

Using Port 443
If my code uses port 443 all the lines within this if-stmt

 if (client.connect(server, portNumber))  

are executed except the line in question. So while it seems certain that I am actually connected to the HTTPS server - because the ‘Connected to …’ and ‘Text sent…’ lines are executed - the text is never received.

Using Port 80
On the other hand, using this HTTP server and the same exact PHP file, the code executes and the text is received.

So my question is this: How can the problem code line be ignored if I am connected to an HTTPS server, yet execute normally if connected to an HTTP server?

I have failed to solve this issue for months so I hope someone can provide some guidance on solving it.

Thank you very much,
Phillip

Are you using the correct protocol version for your HTTPS server? If your HTTPS server supports a different version of HTTP than your HTTP server, you might need to specify it in your code. For example, if your HTTPS server supports HTTP/2, you might need to change your code to:`client.println(“POST /includes/test_text.php HTTP/2”)

All data over port 443 is encrypted using SSL, but it looks like your implementation is just sending plain text to it, which it won’t recognize.

You could try using something like cURL to connect, which is available in most programming languages. Or alternatively look up how to make https request in the language you are using.

1 Like

What is client in this context?
Is the sending server capable of sending TLS 1.2 communication? (How old is your OS…)
Is the receiving server capable of receiving TLS 1.2 communication?

Where does PHP come into this other than the file being requested? The code you’re showing us isnt PHP. That’s not how PHP defines variables or functions.

@lara @rpkamp @m_hutley

I want to say Thank You! for taking your time to help me with this nagging server problem.
I will respond to each of your comments and suggestions separately.

You are welcome! I look forward to hearing from you and hope we could help you with your server problems.

It sounds like you are so busy or dealing with frustration but no issues take your time. :tired_face: I look forward to hearing from you and learning more about your progress.

Please let me know if you have any other questions or concerns.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.