
LSL
CODE
// Global variables
key http_request_id;
integer inUse = FALSE;
string usrName;
string usrKey;
integer password;
string phpForm = "http://www.mywebsite.com/register.php";
// Split function on "|"
string splitf(string strSplit, integer i)
{
list split = llParseString2List(strSplit, ["|"],[]);
return llList2String(split, i);
}
default
{
touch_start(integer total_number)
{
if (inUse) {
llSay(0, "System registering "+ usrName +", Please wait.");
} else {
inUse = TRUE;
usrName = llKey2Name(llDetectedKey(0));
password = llRound(llFrand(899)+100);
http_request_id = llHTTPRequest(phpForm, [HTTP_METHOD,"POST",HTTP_MIMETYPE,"application/x-www-form-urlencoded"], "&password="+ (string)password + "&username="+ usrName);
}
}
http_response(key request_id, integer status, list metadata, string body)
{
if (request_id == http_request_id && status == 200)
{
if (splitf(body, 0) == "usrReg")
{
if (splitf(body, 1) == "ok")
{
llInstantMessage(usrKey, "Your Login name is: "+ usrName + ". Your password is "+ (string)password +".");
}
if (splitf(body, 1) == "fail")
{
llInstantMessage(usrKey, "Registration failed, error: "+ splitf(body, 2));
}
inUse = FALSE;
}
} else {
llSay(0, "Website encounterd a problem, please try again later.");
}
}
}
CODE
<?php session_start();
$hostname='myhost';
$username='myuser';
$password='mypass';
$dbname='mydatabase';
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
// username and password sent from SL
$myusername=$_POST['username'];
$mypassword=$_POST['password'];
//I want to verify if the user exists already
$sql="SELECT * FROM jos_users WHERE username='$myusername' ";
$result=mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$username = $row['username'];
}
$sql1="SELECT * FROM jos_users WHERE username='$myusername'";
$result1=mysql_query($sql1);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result1);
// If result matched $myusername, table row must be 1 row
if($count==1)
//I have no idea if this is right in regard to the http_response in the LSL
{
echo "You are already registered";
}
else
{
//This is the encryption to convert the password to joomla database - I am pretty sure this part is right, at least the conversion
$part = explode(":",$password);
$salt = $part[1];
$encrypted_password = md5($mypassword . $salt).":".$salt;
;
//The following is updating the user information into the four tables necessary to register someone in joomla. the number of tables and information is correct, though someone may want to look at my code
mysql_query("INSERT INTO jos_users (name, username, password) VALUES('$myusername' , '$myusername' , '$encrypted_password' ) ");
$id1 = mysql_connect();
mysql_query("INSERT INTO jos_comprofiler (id, user_id) VALUES ('$id1' , '$id1' ) ");
mysql_query("INSERT INTO jos_core_acl_aro (value, name) VALUES ('$id1' , '$username' ) ");
$id2 = mysql_connect();
mysql_query("INSERT INTO jos_core_acl_groups_aro_map (group_id, aro_id) VALUES ('18' , '$id2' ) ");
}
//Do I need to echo something for the http_response
mysql_close();
?>
Again thanks in advance and once I get this working I will post the final code as I know there are many joomla/sl users out there.
Web
. It would be worth taking that out. It shouldn't be a problem really, but it's worth being thorough!