Shoutbox

Sending data to online forms - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Sending data to online forms (/showthread.php?tid=63894)

Sending data to online forms by absorbation on 07-24-2006 at 11:22 AM

Now, I am creating something, something special, but I have run into a spot of bother. I want to send data from a Plus! script to a form online, which will then add data to a database. Problem is, this is something I really do not understand and I want it secure. I am confused about sending data from a script into <input> fields online. So if anyone has any basic examples or any tips to make sure it is secure it would really help :).

Thanks :).


RE: Sending data to online forms by -dt- on 07-24-2006 at 11:27 AM

take a look at this
http://shoutbox.menthix.net/showthread.php?tid=63...d=694150#pid694150

its a bit more complex than you want... but its still an example of POST'ing data


RE: Sending data to online forms by Ezra on 07-24-2006 at 11:27 AM

You can't send the data to <input> fields, you have to send it to the php whatever script directly, using preferably POST.

code:
var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open ("POST", postaddress, true);
http.send (postdata);


Something like that.

Securing it, could only be done by using SSL, but you need a server that can handle SSL traffic.
RE: Sending data to online forms by absorbation on 07-24-2006 at 11:40 AM

Well Ezra, a real example would help a lot, just something to point to a script online and send a PostAddress variable to it. I then can work my way into things by myself :).


RE: Sending data to online forms by Ezra on 07-24-2006 at 11:46 AM

Well, that one kinda worked already...

code:
var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open ("POST", "http://www.absorbation.com/script.php", true);
http.send ("The data you want to sent...");


That can be retrieved with the php GET_RAW_POST_DATA function.

code:
var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open ("POST", "http://www.absorbation.com/script.php", true);
http.send ("?name=absorbation&status=online");


This can be retrieved simply by using $_POST['name'] and $_POST['status']

EDIT:
http://www.w3schools.com/ajax/ajax... Also read that, tells you about the xmlhttprequest functions

RE: Sending data to online forms by RaceProUK on 07-24-2006 at 12:05 PM

quote:
Originally posted by Ezra
code:
var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open ("POST", "http://www.absorbation.com/script.php", true);
http.send ("?name=absorbation&status=online");


That snippet seems to bear more resemblance to a GET request, where vars are in the URL.
RE: Sending data to online forms by absorbation on 07-24-2006 at 12:06 PM

I am having some slight trouble, what is wrong here? :P

My index.php file: ($con varible is missing for obvious reasons)

code:
$value= mysql_real_escape_string($_POST['value']);
mysql_query("insert into personalmessages values('','1','$value','time')");
mysql_close($con);

And my script code:

code:
function OnEvent_MyPsmChange(NewPsm)
{
var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open ("POST", "http://bananaphone.absorbation.com/index.php", true);
http.send ("?username=absorbation?password=password?feild=psm?value=testing");
}

I know it is sending something, as every time I change my personal message the database has a value added to it. The problem is, it is not adding the $value variable, any ideas why? :)
RE: Sending data to online forms by Dempsey on 07-24-2006 at 12:11 PM

quote:
Originally posted by absorbation

I know it is sending something, as every time I change my personal message the database has a value added to it. The problem is, it is not adding the $value variable, any ideas why? :)
Could it be because you have

http.send ("?username=absorbation?password=password?feild=psm?value=testing");

And the script is expecting field?

RE: Sending data to online forms by Ezra on 07-24-2006 at 12:13 PM

quote:
Originally posted by absorbation
code:
function OnEvent_MyPsmChange(NewPsm)
{
var http = new ActiveXObject("Microsoft.XMLHTTP");
http.open ("POST", "http://bananaphone.absorbation.com/index.php", true);
http.send ("?username=absorbation?password=password?feild=psm?value=testing");
}


Only the first variable should have a question mark the next should have an ampersand (&)

code:
?username=absorbation&password=password&feild=psm&value=testing


EDIT: searching a little about it, I don't think you need that first questionmark.

code:
username=absorbation&password=password&feild=psm&value=testing


Should do the trick

RE: Sending data to online forms by absorbation on 07-24-2006 at 12:15 PM

quote:
Originally posted by Dempsey
Could it be because you have
http.send ("?username=absorbation?password=password?feild=psm?value=testing");
And the script is expecting field?

Nope, I am not currently using that variable, what I have posted is the whole of my code, apart from the $con variable. I am just trying to receive the $value variable at the moment :).

quote:
Originally posted by Ezra

Only the first variable should have a question mark the next should have an ampersand

Still not picking it up :(:

code:
http.send ("?username=absorbation&password=password&feild=psm&value=testing");

And your question mark idea still does not pick up the variable. I am beginning to think it is a problem with index.php? :P
RE: Sending data to online forms by J-Thread on 07-24-2006 at 12:51 PM

Remove the first ? as Ezra already said, and it should work...


RE: Sending data to online forms by absorbation on 07-24-2006 at 12:53 PM

quote:
Originally posted by J-Thread
Remove the first ? as Ezra already said, and it should work...

Already done, and still it does not pick up the value variable :(.
RE: Sending data to online forms by Ezra on 07-24-2006 at 01:06 PM

I found out why it works with RAW and not with the $_POST variables. PHP doesn't know the encoding type.

So you have to set the requestheader

code:
function OnEvent_MyPsmChange(NewPsm)
{
  var http = new ActiveXObject("Microsoft.XMLHTTP");
  http.open ("POST", "http://www.absorbation.com/whatever.php", true);
  http.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
  http.send ("username=absorbation&password=pass&field=psm&value=" + NewPsm);
 
}


RE: Sending data to online forms by absorbation on 07-24-2006 at 01:11 PM

Thanks, it finally works, thank you, thank you :D.


RE: RE: Sending data to online forms by mickael9 on 07-24-2006 at 02:29 PM

quote:
Originally posted by Ezra
I found out why it works with RAW and not with the $_POST variables. PHP doesn't know the encoding type.

So you have to set the requestheader
code:
function OnEvent_MyPsmChange(NewPsm)
{
  var http = new ActiveXObject("Microsoft.XMLHTTP");
  http.open ("POST", "http://www.absorbation.com/whatever.php", true);
  http.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
  http.send ("username=absorbation&password=pass&field=psm&value=" + escape(NewPsm));
}


(A)
RE: Sending data to online forms by cloudhunter on 07-24-2006 at 07:08 PM

The escape(NewPsm) isn't needed at all... That isn't needed to append the value onto another command/string, and is only needed when you are gonna return a different PSM due to the value in the other PSM.

Cloudy


RE: Sending data to online forms by deAd on 07-24-2006 at 07:12 PM

I think you meant encodeURI(NewPsm)...it is a good practice to encode the variable values with this function, it helps eliminate some errors.