Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Dreamhost - XML-RPC, PhP, LSL

Prometheus Deckard
Registered User
Join date: 24 May 2005
Posts: 23
04-29-2006 14:54
A RL friend of mine and I were going to start out on a project for SL, although I have very limited knowledge in XML-RPC and PhP. I've run some searchs on the forums, and am slightly familiar now with this, although would be greatly appreciated if someone could take me through step-by-step, or atleast broaden my knowledge.

First off, Dreamhost. I'm using Dreamhost as my 'web-hosting provider'. I've learned that in order to start a channel via XML-RPC from LSL to PhP, i'll need to E-mail the PHP script. How can I set up a DreamHost E-mail account to route the E-mails to a specific route? Anyone have a link or guide on this?

As I stated about, my knowledge is VERY limited when it comes mainly to PHP. I was wondering if anyone had an example PHP script that could recieve info via SL, and store it in a database (or, if not the database part, atleast recieveing info (Starting small :P)). For the database, I'm not quite sure how to properly set it up via DreamHost, so if anyone has a guide on that, or if it's simple, can just let me know, would be awesome.

php - As I've seen in some PHP scripts including XML-RPC, I need some things which only I can get, such as localhost, and e-mail information. Does anyone know how to get this information from DreamHost (A link?)

LSL - To start off, I'll probably just start with sending small strings, so I'll keep looking for more example scripts to learn off of.

Thanks in advance to anyone who understood what I said (pretty sure most of it is jumbled or doesn't make sense).
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
04-29-2006 15:02
Given that 1.9.1 will include a function for making straight HTTP requests, it's probably not worth your while to learn to deal with XML-RPC if you don't already know PHP.
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
04-29-2006 15:15
Yeah, echoing that - wait for 1.9.1, it eliminates the need for a lot of the hassle in setting up external coms.
_____________________
Co-Founder / Lead Developer
GigasSecondServer
Prometheus Deckard
Registered User
Join date: 24 May 2005
Posts: 23
04-29-2006 15:29
Awesome =D Although I don't know PHP. Would still be nice to see any example scripts for these problems though, even if I won't be using them (Unless I get a real nice feel for it)
Prometheus Deckard
Registered User
Join date: 24 May 2005
Posts: 23
04-29-2006 23:42
Hmm. Just occured to me, do you mean with HTML I won't need to use XML-RPC, or it'll just be easier to start the channel (Like no E-mail?)
Rodrick Harrington
Registered User
Join date: 9 Jul 2005
Posts: 150
04-30-2006 10:26
email to php script for dreamhost

first create a shell account and email address for the account. Then in the home directory put this code named ".forward.postfix"

CODE
|/home/<username>/path/to/script.php


Then in your php script . . .

CODE
#!/usr/local/bin/php
<?php
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd))
{
$email .= fread($fd, 1024);
}
fclose($fd);
// handle email
$lines = explode("\n", $email);

// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;


for ($i=0; $i < count($lines); $i++)
{
if ($splittingheaders)
{
// this is a header
$headers .= $lines[$i]."\n";
// look out for special headers
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches))
{
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches))
{
$from = $matches[1];
}
} else {
// not a header, but message
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="")
{
// empty line, header section has ended
$splittingheaders = false;
}
}

//now do something with the information contained in the email
Prometheus Deckard
Registered User
Join date: 24 May 2005
Posts: 23
04-30-2006 10:34
When you say 'Home directory', would that be the root folder of the whole server?

|/home/<username>/path/to/script.php

^ - <username> - Would I need to change that?

Thanks for the script =D. Helped a bit, although still need to find out how to initialize a XML-RPC channel via having the object e-mail the server.
Prometheus Deckard
Registered User
Join date: 24 May 2005
Posts: 23
05-01-2006 17:27
Bump

Okay, with the help of some friends, I've managed to get 'some' of this down, although I'm still not sure how to access a database via PHP. Any help would be appreciated :D
Androclese Antonelli
Org. B-Day: 05/11/04
Join date: 25 Apr 2006
Posts: 96
05-01-2006 19:40
From: Prometheus Deckard
Bump

Okay, with the help of some friends, I've managed to get 'some' of this down, although I'm still not sure how to access a database via PHP. Any help would be appreciated :D


Well, you are in luck. I'm a PHP coder by trade. What you are asking for, I'm assuming, is how do you connect to a mySQL database through PHP.

If that is the case, I'll show ya. (just remember... you asked for it...)

Now. To start, you need the following.

mySQL Database Information:
  1. DB name
  2. username
  3. password
Now, please make note, I keep my DB access into in a separate file to keep it safe from prying eyes. I then include that info into the main page, checking for a constant variable. if the variable it not there, it breaks the process. You can conbine the files if you wish, but I do not reccomend it.


Also, please note. This is not a PHP class. It's just a basic example of what can be done and, hopefully, gives you something to work from.

Lets say you have a database called sl_stuff

Inside that db, you have a table called keys


The table keys has the following columns within it:
  1. key_id //The table row
  2. key_value //The key value
In this example, we only really care about the column key_value and the data stored within.




So, lets start with the db connection information:


Call this file db.php
CODE
<?php

if ( !defined('HACK_PROT') )
{
die("Hacking attempt");
}

/*------------------------------------------------------*\
Standard mySQL Connection strings

These sub-routines will be refferenced by all
scripts to access the mySQL dB.
\*------------------------------------------------------*/

/*------------------------------------------------------*\
Variable Definitions
\*------------------------------------------------------*/
$mysql_host;
$mysql_user;
$mysql_password;
$mysql_db;

/*------------------------------------------------------*\
User Set Variables
\*------------------------------------------------------*/
$mysql_host = "localhost";
$mysql_user = "USERNAME";
$mysql_password = "PASSWORD";
$mysql_db = "sl_stuff";

/*------------------------------------------------------*\
DO NOT Edit anything below this line unless you
EXACTLY what you are doing to the code!!!
\*------------------------------------------------------*/

// Connecting, selecting database
$sqlopen = mysql_connect($mysql_host, $mysql_user, $mysql_password)
or die("Could not connect: " . mysql_error());

mysql_select_db($mysql_db) or die("Could not select database");

?>


Just replace the access variables.



Now for the actual connection stuff.



Call this file anything you want. Me, I'd call it sl_stuff.php but that's just me:



CODE

<?php



define('HACK_PROT', TRUE);
define('DEBUG', TRUE);
$root_path = './';

include_once($root_path . 'db.php');

$sql = ("SELECT * FROM keys");

if ( DEBUG ) {echo "$sql\n\n";}
$sqlresult = mysql_query($sql) or die( mysql_error() );

while ($results = mysql_fetch_array($sqlresult, MYSQL_ASSOC)) {
print ("$results[key_value]\n");
$SLkeys[] = $results[key_value];

}




That's pretty much it. All the contents of the DB will be printed out and stored into the array $SLkeys. Past here, you'll need to pull the data from the Array and process it.... something that is probably better done in a PHP specific forum.



I hope this helps and gets your off the ground.
_____________________
The Sculpted Garden

Originally Born 5/11/2004 - New AV, Old Player.

If you leave the game, don't delete your account, just make it 'free'. You'll lose your inventory like I did. *sniff*