Jump to content
Sign in to follow this  
Moore Tone

llHTTPRequest issue: seems don't send GET vars

Recommended Posts

Sorry to bother for a silly question like that, but it puzzles me about 2 hours.
What I want is simply send by lsl a GET var to a php page and get the same value as answer in the http_response( )

Here what I wrote:

LSL script:

string myurl ="http://*****/test0.php"; //obfuscate for privcy : P
key http_request_id;

default
{
  state_entry() { llOwnerSay("Run"); } //don't do nothing special

  touch_start(integer total_number)
  {
    llOwnerSay("Touched.");

    http_request_id = llHTTPRequest(
      myurl, 
      [HTTP_METHOD, "GET", HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
       "p2=test");
  }//touch_start

  http_response(key request_id, integer status, list metadata, string body)
  {
    if (request_id != http_request_id) return;// exit if unknown
    llOwnerSay("-" + (string)status + " - " + body  + "- ");
  }
}

 -----

PHP code:

<?php
$servervar1 = "nothing here";

if( $_GET['p2'] != NULL ){
  $servervar1 = $_GET['p2'];
} else {
  $servervar1 = "p2 var is NULL or doesn't exist";
}

echo("--".$servervar1."--".);
?>

 -----

Everything goes fine  with no problem but despite any effort I keep get the FAIL message:

-200 - --p2 var is NULL or doesn't exist--- 

I also checked the same url via browser and it works correctly

I also checked using the LSL script if -any- $_GET[ ] reach the php page counting the length of the $_GET[ ] array (...sizeof($_GET)...) but keep telling me 0 elements.

So, seems my php page don't see the GET var coming from the LSL script..but don't have any idea why!
 -----

Somebody could help me?

Share this post


Link to post
Share on other sites

Just to elaborate on what ObviousAltIsObvious said:

The $_GET variable in PHP get populated by the key-value-pairs in the URL of a GET request. You put your values in the body of the HTTP-request, not in the URL, so the $_GET variable in PHP will be empty. The body is used in a POST request to pass the key-value-pairs.

  • Like 1

Share this post


Link to post
Share on other sites

Thank you for both answers, with your clear explanations I understood what I was doing wrong and now it works with no problem at all.

Now I'm able to send vars both via GET or POST with no more headache!
Really thank you two!

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...