Author Topic: Writing a line to a website  (Read 5500 times)

I know that you can retrieve lines from a website using TCP objects and .send("GET... Blah blah blah") and read the lines, but can you write a line to a website?

Use TCPObject::send() terminated with a \n (optionally with a \r before it for certain messed up platforms or servers).

So if I have an HTML file on my website (for example, an admin cloud), I could create a line on the file on the website using TCPObject::send()?

Why not use HTTPobject.get()? It's far simpler.

Why not use HTTPobject.get()? It's far simpler.
I think you're not getting what I'm trying to say. Wouldn't using .get() retrieve the line, as in read it? I'm wondering how to add a line.

For example, if I had a database that looked like this on a website of mine:
BLID    Value
35041  125
48290  204
1458    67

And I wanted to write a line in the database, such as BLID "2638" and value "206", how would I do so using torquescript?
 

you'll have to have a script on the server to write to the file

I think you're not getting what I'm trying to say.
Oh, I wasn't responding to the OP. I meant that using an HTTP object to retrieve data from a web site is much easier than raw TCPobjects.

You need some sort of server side script running, not just a plain HTML file

Wouldn't using .get() retrieve the line, as in read it?
Not really. I'm not sure how well Torque implements it, but GET and POST both send HTTP requests to the server, just that in a POST, the data is sent in the HTTP message body, while in a GET, it's sent in the url. Once you have the data, you can use it however you want.

Oh, I wasn't responding to the OP. I meant that using an HTTP object to retrieve data from a web site is much easier than raw TCPobjects.
I'm pretty sure I've heard about something stuffty about Torque's implementation of HTTP objects that makes TCPObject usage preferred. I can't remember what it is, though
« Last Edit: June 08, 2014, 10:28:05 PM by Headcrab Zombie »

Well yes, you can. You need PHP or node.js to do server sided scripting. (PHP is the most popular and known choice, but id rather have node.js)

Your webhost needs to support PHP (unless you are using a VPS, which you install PHP manually)

Use TCP magic to send the data, and the server to handle it.

TCPObject.send(%data @ "\r\n");

Not going to go indepth of TCP objects, may post a tutorial on TCP objects very soon, just got lazy on it.

Learn how to use PHP (variables functions ect), and Google up handing GET/POST requests in PHP + file writing

make a php script something like

Code: [Select]
<?php
$line 
$_POST["info"];
$pass $_POST["pass"];
if(
$pass != "somekindofpassword")
return;
$fp fopen("admins.html"'a');
fwrite($fp,$line PHP_EOL);
fclose($fp);
?>

then you can send a post method to the php script with a simple pass key to prevent people from loving with it and the line of text

then you can send a post method to the php script with a simple pass key to prevent people from loving with it and the line of text

Except a simple pass key in a open source add-on is pretty pointless. Just about anyone who knows how to do any of this could easily find the password in the add-on. Of course, if your keeping it to yourself then that's fine.


This is going to sound weird, but I think I have around 8 TCP tutorials favorited, but if you have another p, please share it!

Also, thanks for the help, guys!

I'm pretty sure I've heard about something stuffty about Torque's implementation of HTTP objects that makes TCPObject usage preferred
Yes, HTTPobject.get() may be badly designed, but HTTPobject.post() is absolutely horrible. I think the thing you heard applies mostly to POST. I think .get() works okay for most applications, if you don't need to specify HTTP headers.

Except a simple pass key in a open source add-on is pretty pointless. Just about anyone who knows how to do any of this could easily find the password in the add-on. Of course, if your keeping it to yourself then that's fine.
this doesn't sound open source
this sounds like he wants to write lines to his own site

Is this even necessary?
I've noticing a small surge of people who want to have cloud-based admin lists and other things, but have no need for doing so cuz they only host a single server
« Last Edit: June 10, 2014, 12:33:00 PM by Headcrab Zombie »