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

[Program] http door security

Started by v3nw, 19 January 2013 - 02:56 AM
v3nw #1
Posted 19 January 2013 - 03:56 AM
First, I apologize for my English bad.

>test link : http://erayarslan.com/door


important
[x] The HTTP API must be enabled in mod_ComputerCraft.cfg before being used. To enable it open .minecraft/config/mod_ComputerCraft.cfg and change enableAPI_http=0 to enableAPI_http=1.



Example's ;

http dir : http://host/door
content file : http://host/door/door.txt
index file : http://host/door/index.php

redstone side : left

program

while true do
  local content = http.get("http://host/door/door.txt")
  local s = content.readAll()
  if s == "1" then
	  redstone.setOutput("left",true)
  elseif s=="0" then
	  redstone.setOutput("left",false)
  end
  sleep(1)
end

index.php

<title>cc - door security system</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
if(isset($_REQUEST['open']))
{
  $islem=fopen("door.txt",'w');
  fwrite($islem,1);
  header("Location: index.php");
}
else if(isset($_REQUEST['close']))
{
  $islem=fopen("door.txt",'w');
  fwrite($islem,0);
  header("Location: index.php");
}
else
{
$icerik= fopen("door.txt",'r');
$x= fread($icerik, filesize("door.txt"));
if($x=="1")
{
$x="opened";
}
else if($x=="0")
{
$x="closed";
}
else
{
$x="unknown";
}
?>
<form method="post" action="index.php">
	<table border="0">
	  <tr>
	<tr>
	  <th> door is </th>
	  <td><?php echo $x; ?></td>
	</tr>
<tr>
  <td colspan="2" align="center"><input type="submit"  name="open" value="open"><input type="submit" name="close" value="close"></td>
</tr>
	</table>
</form>
<?
}
?>

door.txt (default is 0 ) 1 = opened , 0 = closed

0
zekesonxx #2
Posted 19 January 2013 - 06:08 AM
Interesting. Good though.
v3nw #3
Posted 20 January 2013 - 03:18 AM
thank you so much :)/>