Registering users on a website

In-world script

Just copy it to a script and place it inside an object in Second Life.

// Code by Gwyneth Llewelyn// Touch to get your avatar name registered remotely// Global Variableskey avatarKey;string avatarName;key registrationResponse; // to send the PermURL to the blogkey webResponse; // to send periodic updates to the blogstring http_host = "my.hostname.tld";string url; default{  state_entry()  {    llSetText("Touch to get registered with " + http_host, <1.0,1.0,1.0>, 1.0);  }  on_rez(integer startParam) {    llResetScript();  }  changed(integer what)  {    if (what & (CHANGED_OWNER | CHANGED_REGION | CHANGED_REGION_START | CHANGED_TELEPORT))      llResetScript();  }  touch(integer howmany)  {    integer i;     for (i = 0; i < howmany; i++)    {      avatarName = llDetectedName(i);      avatarKey = llDetectedKey(i);      llSetText("Sending registration for " + avatarName + "...",        <1.0,0.0,0.0>, 1.0); // call the site with data      string message = "action=register" + "&avatarName=" + llEscapeURL(avatarName)        + "&avatarKey=" + llEscapeURL(avatarKey);      registrationResponse = llHTTPRequest("http://" + http_host + "/registerAvatar.php",         [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], message);    }  }  // Catching reply from web server  http_response(key request_id, integer status, list metadata, string body)  {    if (request_id == registrationResponse)    {      if (status == 200)      {        llOwnerSay("Avatar registration sent to gateway! Msg. id is " + body);      }      else if (status == 499)      {        llOwnerSay("Timeout waiting for gateway! Your PermURL might still be sent, please be patient");      }      else      {        llOwnerSay("PermURL NOT sent. Status was " + (string)status + "; error message: " + body);      }      llSetText("Touch to get registered with " + http_host, <1.0, 1.0, 1.0>, 1.0);    }  }}

Database setup

Create a database table on your MySQL server with the following code:

| ← Previous | | | Next → |
%d bloggers like this: