Jump to content
Sign in to follow this  
Gregory McLeod

HTTPRequest header missing

Recommended Posts

I am using an HTTPRequest from a prim script

   SERVER_REQ_ID = llHTTPRequest( SERVER_URL+"&id="+(string)id, [], "" );

I naively thought that all httprequests were accompanied by the Second_life Headers.

The one I am missing is X-SecondLife-Owner-Key this results in an php script error and the returned data is invalid.

Do you have to use one of the GET or POST methods to get SL to send the full headers?

 

If so I wonder how this used to work, as it did.

Share this post


Link to post
Share on other sites

I assume you mean in the PHP script.

If so yes the setting $USE_APACHE_HEADERS = TRUE;

but I am so much a beginner at this that I don't know what it means.

Help please.

Share this post


Link to post
Share on other sites

To try to resolve what I think may be a misunderstanding between us Darkie I show the whole of the PHP script that is being called and the method of calling.

The method of calling

<q>

string  SERVER_URL  = "http://awebsite.com/folder1/folder2/manager.php?action=UPDATE";
key     SERVER_REQ_ID;
integer id;

id = -1;

request_server() {
    SERVER_REQ_ID = llHTTPRequest( SERVER_URL+"&id="+(string)id, [], "" );
}

other lines of code

</q>

the receiving website manager.php

<q>

<?php

include_once('bin/DBHandler.php');

$USE_APACHE_HEADERS = TRUE;
// switch to false if you need cgi methods
if ($USE_APACHE_HEADERS)
{
 $headers    = apache_request_headers();
 $objectgrid = $headers["X-SecondLife-Shard"];
 $objectname = $headers["X-SecondLife-Object-Name"];
 $objectkey  = $headers["X-SecondLife-Object-Key"];
 $objectpos  = $headers["X-SecondLife-Local-Position"];
 $ownerkey   = $headers["X-SecondLife-Owner-Key"];
 $ownername  = $headers["X-SecondLife-Owner-Name"];
 $regiondata = $headers["X-SecondLife-Region"];
 $regiontmp  = explode ("(",$regiondata); // cut cords off
 $regionpos  = explode (")",$regiontmp[1]); //
 $regionname = substr($regiontmp[0],0,-1); // cut last space from simname
} else {
 $db = $GLOBALS;
 $headers    = $db['HTTP_ENV_VARS'];
 $objectgrid = $headers["HTTP_X_SECONDLIFE_SHARD"];
 $objectname = $headers["HTTP_X_SECONDLIFE_OBJECT_NAME"];
 $objectkey  = $headers["HTTP_X_SECONDLIFE_OBJECT_KEY"];
 $ownerkey   = $headers["HTTP_X_SECONDLIFE_OWNER_KEY"];
 $objectpos  = $headers["HTTP_X_SECONDLIFE_LOCAL_POSITION"];
 $ownername  = $headers["HTTP_X_SECONDLIFE_OWNER_NAME"];
 $regiondata = $headers["HTTP_X_SECONDLIFE_REGION"];
 $regiontmp  = explode ("(",$regiondata);
 $regionpos  = explode (")",$regiontmp[1]);
 $regionname = substr($regiontmp[0],0,-1);
}

if(!isset($ownerkey)) {
 print "INVALID_ACCESS";; 
}

$db = new DBHandler();

function createSurl($reg, $p) {
 $p = str_replace ( "(" , "" , $p );
 $p = str_replace ( ")" , "" , $p );
 $c = split ( "," , $p);
 return "secondlife://$reg/$c[0]/$c[1]/$c[2]";
}

$action = $_GET['action'];
switch($action) {
 case "UPDATE":
  $id = $_GET['id'];
  if( is_numeric ($id) ) {
   if($id == -1) {
    $index = $db->getLastIndex() + 1;
    if($db->addField($index, $ownername, createSurl($regionname, $objectpos)))
     print "NEW,$index";
    else
     print "Database Error";
   }
   else if($id > 0) {
    if($db->isField($id)) {
     if($db->updateField($id, $ownername, createSurl($regionname, $objectpos)))
     {
      if($db->isFieldActive($id)) 
       print "ENABLE";
      else
       print "DISABLE";
     }
     else {
      print "DISABLE";
     }
    }
    else if($db->addField($id, $ownername, createSurl($regionname, $objectpos)))
     print "NEW,$index";
    else
     print "Database Error";
   }
  }
  else
   print "INVALID";
 break;
}

</q>

Note in this PHP script there is an incompatability between the code and the PHP version in the statement

<q>

function createSurl($reg, $p) {
...

 $c = split ( "," , $p);

...

</q>

which is what got me into this mess in the first place. I have fixed that by changing the split to a preg_split as in

$c = preg_split( '[(,)]' , $p );

The result that the prim receives from the request is

INVALID_ACCESSINVALID

which suggest to me that the $ownerkey is not being set.

Do you have any comments?

Share this post


Link to post
Share on other sites

This PHP script returns all headers.

<?php  foreach ($_SERVER as $key => $value) {    if (strpos($key, 'HTTP_') === 0) {      $chunks = explode('_', $key);      $header = '';      for ($i = 1; $y = sizeof($chunks) - 1, $i < $y; $i++) {        $header .= ucfirst(strtolower($chunks[$i])).'-';      }      $header .= ucfirst(strtolower($chunks[$i])).': '.$value;      echo $header.'<br>';    }  }?>

 You could check them with:

    http_response(key id, integer s, list data, string body) {        list b = llParseString2List(body, ["<br>"], []);        integer l;        do {            llOwnerSay(llList2String(b, l));        } while (++l < llGetListLength(b));    }

 Then you know if your owner key header is available or not.

Share this post


Link to post
Share on other sites

That has provided an answer which works, thank you.

I was trying to use the examples in the link provided before and just could not get them to work.

Now I have working lsl and php scripts I can expand on them to find out what is happening in my HUD.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...