Arduino Nano with ENC28j60: EtherCard Get parameter not send if I use c_str()

If I do this:

  String param = "?ringUid=";
  param.concat(ringUid);
  param.concat(F("&loggerid=1"));
  const char* p = param.c_str();
  ether.browseUrl(PSTR("/nfclog.php"), p, website, my_callback);

then $_GET php global array is empty.
Apache access.log:

192.168.1.150 - - [19/Jan/2022:10:21:26 +0000] "GET /nfclog.php HTTP/1.0" 200 318 "-" "-"

If I do this:

ether.browseUrl(PSTR("/nfclog.php"), "?ringUid=a1b2c3d4&loggerid=1", website, my_callback);`

then everithing fine, I get $_GET array at server side.

Apache access.log:

192.168.1.150 - - [19/Jan/2022:10:26:24 +0000] "GET /nfclog.php?ringUid=a1b2c3d4&loggerid=1 HTTP/1.0" 200 303 "-" "-"

What do I wrong? Why not passed the parameter to the query?

If I do this:

      char p[param.length()+1];
      sprintf(p,"?ringUid=%s&loggerid=1",ringUid.c_str()); 
      ether.browseUrl(PSTR("/nfclog.php"), p, website, my_callback);

I get HTTP error (400 Bad Request).
Apache access.log contains this:

192.168.1.150 - - [19/Jan/2022:10:11:34 +0000] "GET /nfclog.php>\x02\xc3\b0\x02\x15\x02V\x01 HTTP/1.0" 400 483 "-" "-"

I don't know the EtherCard library, but I guess the GET request is executed after the string variables go out of scope and are removed from stack.
show us a complete sketch

#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>

#include <EtherCard.h>

PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[700];
static uint32_t timer;

const char website[] PROGMEM = "rpi1.me.local";

static void my_callback (byte status, word off, word len) {
  Serial.println(">>>");
  Ethernet::buffer[off+300] = 0;
  Serial.print((const char*) Ethernet::buffer + off);
  Serial.println("...");
}

void setup () {
  Serial.begin(9600);
  Serial.println(F("\n[webClient]"));

  // Change 'SS' to your Slave Select pin, if you arn't using the default pin
  if (ether.begin(sizeof Ethernet::buffer, mymac, SS) == 0)
    Serial.println(F("Failed to access Ethernet controller"));
  if (!ether.dhcpSetup())
    Serial.println(F("DHCP failed"));

  ether.printIp(F("IP:  "), ether.myip);
  ether.printIp(F("GW:  "), ether.gwip);
  ether.printIp(F("DNS: "), ether.dnsip);

  if (!ether.dnsLookup(website))
    Serial.println(F("DNS failed"));

  ether.printIp(F("SRV: "), ether.hisip);


  Serial.println(F("Looking for PN532..."));

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print(F("Didn't find PN53x board"));
    while (1); // halt
  }
  
  // Got ok data, print it out!
  Serial.print(F("Found chip PN5")); Serial.println((versiondata>>24) & 0xFF, HEX); 
  Serial.print(F("Firmware ver. ")); Serial.print((versiondata>>16) & 0xFF, DEC); 
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
 
  // configure board to read RFID tags
  nfc.SAMConfig();

  
}

void loop () {
  ether.packetLoop(ether.packetReceive());

  if (millis() > timer) {
    boolean success = false;
    uint8_t uid[] = {0, 0, 0, 0, 0, 0, 0};  // Buffer to store the returned UID
    uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type
    success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
    if (success) {
      String ringUid = "";
      for (uint8_t i=0; i<uidLength; i++){
        if(uid[i] < 0x10) {
          ringUid += '0';
        }
        ringUid += String(uid[i], HEX);
      }
      String param = "?ringUid=";
      param.concat(ringUid);
      param.concat(F("&loggerid=1"));
      const char* p = param.c_str();
      //char p[param.length()+1];
      //sprintf(p,"?ringUid=%s&loggerid=1",ringUid.c_str());
      ether.browseUrl(PSTR("/nfclog.php"), p, website, my_callback);
      //ether.browseUrl(PSTR("/nfclog.php"), "?ringUid=a1b2c3d4&loggerid=1", website, my_callback);
      Serial.println(p);
      Serial.print(F("<<< REQ "));
    }  
    timer = millis() + 5000;
  }
}

char* string2char(String command){
    if(command.length()!=0){
        char *p = const_cast<char*>(command.c_str());
        return p;
    }
}

If I modify EtherCard WebClient example added p parameter to browseUrl I get same result.

make param a global variable.

btw. there is a better Arduino library for enc28j60. the EthernetENC library

Thanks, it works. But Why? I don't understand.

I guess only packetLoop process the request. At that time param doesn't exist if it is local in the if block