Search code examples
phplinden-scripting-language

Issue with lsl to php script


PHP part:

$php = $_POST['php'];

//$php = "print \"hello world\";";

if ($php != null){
    if (strlen($php) < 400){
        echo $php;
        eval($php);
        //eval("print \"hello world\";");
    }else die ("Evaluated Expression Exceeds Maximum Length");
}

LSL part:

string php = "print \"hello world\";";

Now I added the commented out bits into PHP to show that it works. And then when the LSL script sends to PHP it returns:

print \"hello world\"; -- this line is from, 'echo $php;'

<b>Parse error</b>:  syntax error, unexpected '&quot;', expecting identifier
(T_STRING) in <b>xxxxxx.php(141) : eval()'d code</b> on line <b>1</b><br />
-- this is the error.

And it is something to do with the the way the two scripts are sending data. I thought maybe had something to do with $php = $_POST['php']; so changed it to $php = $_POST[php]; With no change to the result. I then tried changing print \"hello world\"; to print 'hello world'; It then just returns the error : T_ENCAPSED_AND_WHITESPACE.

I did not supply the full source here. Only the section that was having an issue. It is supplied in a example state. The output is the same as the actual error result, that is being seen in the source. Usage of eval is required for the lsl script and php. In that the code is dynamically being reconfigured by both and sent to one another. Essentially giving the two the ability to code into one another. This is for a game in Second Life.

So if anyone knows of an actual way to pass the required data to and from the scripts. I could use some advice. Or a smack in the head if I missed something simple.


Solution

  • With the kind poke from mario on turning off magic_quotes. I then found what the data was doing in the source. I then ended up researching and using the following : eval(stripslashes($php)); Which completely solves the issue. And based on marios poke.

    It had nothing to do with escape data. Didn't think so as echo reported that fine. And it was indeed a slap me in the head error too.

    stripslashes — Un-quotes a quoted string

    Will vote this as best answer and also a best answer for mario. Wish he would have done his as a answer over comment. So could have voted it.