This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
EveryOS's profile picture

Make response on serverside

Started by EveryOS, 29 April 2016 - 12:04 PM
EveryOS #1
Posted 29 April 2016 - 02:04 PM
I have lua:

response = http.post('https://ccraft-jasongronn.c9users.io/test.php')
print(reponse.readAll())
And I have PHP:
[php]<!doctype PHP>
<php>
<?php
date_default_timezone_set("America/New_York");
$hour = date('h')%13;
$luaTime = date($hour.':i a');
echo $luaTime;
?>
</php>[/php]

It keeps giving me the PHP code as a response. Can I send a custom reponse?
Dragon53535 #2
Posted 29 April 2016 - 02:46 PM
Shouldn't you technically use http.get?
EveryOS #3
Posted 29 April 2016 - 02:59 PM
Shouldn't you technically use http.get?
Well, that makes it harder to use URL php variables.
Also, I think http.get would make it worse, because that's even more likely to send the code, tags and all, and that's just what I don't want to do.
Edited on 29 April 2016 - 01:00 PM
Bomb Bloke #4
Posted 29 April 2016 - 03:06 PM
It'll "work" either way, so long as your PHP server is doing its job.
EveryOS #5
Posted 29 April 2016 - 03:14 PM
It'll "work" either way, so long as your PHP server is doing its job.
And what should I do to send a real response rather than HTML (or PHP, or hypertext preprocessor, or whatever)
Bomb Bloke #6
Posted 29 April 2016 - 03:19 PM
Leave the PHP server running, I guess? Putting aside your typo in "response", it works as-is.
EveryOS #7
Posted 29 April 2016 - 03:27 PM
I originally named 'response' 'request'. That was an editing error.

Leave the PHP server running, I guess?

At the time, it's running. That is, however, one of my concerns.
EveryOS #8
Posted 29 April 2016 - 07:23 PM
What I mean is
I want this:

(No HTML)(No whitespace)(PHP response)

Rather than:

(HTML)(whitespace)(PHP content)

This is probably a problem with my PHP code not using a response, but I don't know how to send a response
Edited on 29 April 2016 - 05:24 PM
Tiin57 #9
Posted 29 April 2016 - 07:26 PM
Instead of


<!doctype PHP>
<php>
  <?php
    date_default_timezone_set("America/New_York");
    $hour = date('h')%13;
    $luaTime = date($hour.':i a');
    echo $luaTime;
  ?>
</php>

You'd want


<?php
date_default_timezone_set("America/New_York");
$hour = date('h')%13;
$luaTime = date($hour.':i a');
echo $luaTime;
?>

That shouldn't produce any whitespace, and definitely no HTML. Of course this is assuming your server is configured correctly to serve PHP.
EveryOS #10
Posted 29 April 2016 - 07:40 PM
Instead of


<!doctype PHP>
<php>
  <?php
	date_default_timezone_set("America/New_York");
	$hour = date('h')%13;
	$luaTime = date($hour.':i a');
	echo $luaTime;
  ?>
</php>

You'd want


<?php
date_default_timezone_set("America/New_York");
$hour = date('h')%13;
$luaTime = date($hour.':i a');
echo $luaTime;
?>

That shouldn't produce any whitespace, and definitely no HTML. Of course this is assuming your server is configured correctly to serve PHP.
But what if it's to a PHP page that can also be accessed via a user? 'Im planning on upgrading on this and adding a browser interference
Tiin57 #11
Posted 29 April 2016 - 07:44 PM
Then have an if statement and a special GET or POST parameter for CC clients to use.
Luca_S #12
Posted 29 April 2016 - 07:44 PM
Instead of


<!doctype PHP>
<php>
  <?php
	date_default_timezone_set("America/New_York");
	$hour = date('h')%13;
	$luaTime = date($hour.':i a');
	echo $luaTime;
  ?>
</php>

You'd want


<?php
date_default_timezone_set("America/New_York");
$hour = date('h')%13;
$luaTime = date($hour.':i a');
echo $luaTime;
?>

That shouldn't produce any whitespace, and definitely no HTML. Of course this is assuming your server is configured correctly to serve PHP.
But what if it's to a PHP page that can also be accessed via a user? 'Im planning on upgrading on this and adding a browser interference

You could probably check the user agent and give a custom one in CC.

Edit: Or do above, but if you put something new to the end of the URL you could just use two scripts. So you should go with POST.
Edited on 29 April 2016 - 05:45 PM
Bomb Bloke #13
Posted 30 April 2016 - 12:57 AM
What I mean is
I want this:
(No HTML)(No whitespace)(PHP response)

And that was and still is exactly what you get.