- ComputerCraft | Programmable Computers for Minecraft
- → remiX's Content
remiX's Content
There have been 469 items by remiX (Search limited from 10-February 22)
#118342 Login using PHP
Posted by
remiX
on 17 May 2013 - 12:31 AM
in
Ask a Pro
Never knew you could do that on webhost
haha
Registration uses the insert query.
Note: You will need to add some anti-spam method to prevent spam of multiple users being created
LUA:
PHP:
Shout if there are any errors
Registration uses the insert query.
Note: You will need to add some anti-spam method to prevent spam of multiple users being created
LUA:
Spoiler
-- Variables local server, username, password = "serveraddress.com" term.clear() term.setCursorPos(1,1) write( "Username: ") username = read() write( "Password: ") password = read() local response = http.post(server, "user=" .. username, "&pass="password) local content = response.readAll() response.close() print(content)
PHP:
Spoiler
<?php
$sql = array();
$sql['host'] = '';
$sql['username'] = '';
$sql['password'] = '';
$sql['database'] = '';
$sql['table'] = '';
if (isset($_POST['user']) & isset($_POST['pass'])) {
$user = $_POST['user']; // Put the user's variable into a php variable
$pass = $_POST['pass'];
$con = mysql_connect($sql['host'],$sql['username'],$sql['password']); // Establish the MYSQL connection
mysql_select_db($sql['database'], $con); // Select the database
// Create a query to see if the user is already in use
// the * is so that it selects all column variables
$query = "select * from ".$sql['table']." where username='$user'";
$result = mysql_query($query, $con);
if (!$result || mysql_num_rows($result) == 0) {
echo 'User already exists.';
return;
}
// User does not exist, lets add them
$query = "insert into ".$sql['table']."(id,username,password) values('','$user','$pass')";
$result = mysql_query($query, $con);
echo !$result ? "An error has occured" : "Registered!"; // Ternary operator :P/>
} else {
// Accessed on a browser or wrong CC information
echo '<h3>Invalid Access!</h3>';
}
?>Shout if there are any errors
#118290 Login using PHP
Posted by
remiX
on 16 May 2013 - 04:38 PM
in
Ask a Pro
1vannn, on 16 May 2013 - 03:20 PM, said:
LUA:
Spoiler
-- Variables local server, username = "serveraddress.com" term.clear() term.setCursorPos(1,1) write( "Username: ") username = read() local response = http.post(server, "user=" .. username) local content = response.readAll() response.close() -- If you're using a free website host, such as 000webhosts, there might be extra text at the end of each file. -- This can be removed using gsub print(content)
PHP:
Spoiler
<?php
$sql = array();
$sql['host'] = '';
$sql['username'] = '';
$sql['password'] = '';
$sql['database'] = '';
$sql['table'] = '';
if (isset($_POST['user'])) {
$user = $_POST['user']; // Put the user's variable into a php variable
$con = mysql_connect($sql['host'],$sql['username'],$sql['password']); // Establish the MYSQL connection
mysql_select_db($sql['database'], $con); // Select the database
// Create a query to see if the user is valid
// the * is so that it selects all column variables
$query = "select * from ".$sql['table']." where username='$user'";
$result = mysql_query($query, $con);
if (!$result || mysql_num_rows($result) == 0) {
echo 'Username does not exist.';
return;
}
$row = mysql_fetch_assoc($result);
// $row now has all the stuff from the database row corresponding with the username entered
// like if the database has a column 'age'
echo $row['age']; // echo the age of the user
} else {
// Accessed on a browser
echo '<h3>Invalid Access!</h3>';
}
?>Untested.. tell me if there are any errors
#118189 Login using PHP
Posted by
remiX
on 16 May 2013 - 08:14 AM
in
Ask a Pro
1vannn, on 15 May 2013 - 11:13 PM, said:
1. Write("Username: ")
2. Send to server
3. CC expects a reply
2. Send to server
3. CC expects a reply
Just send the username?
What must be returned back?
Nexus, on 15 May 2013 - 11:53 PM, said:
Here I have the solution for you: my OS! Viewing the source code of the API Nexos, doLogin() function
Good Luck!
EDIT: If you have any questions do not hesitate
Good Luck!
EDIT: If you have any questions do not hesitate
He's wanting the php code too.
#115228 [Question] A little question :P
Posted by
remiX
on 04 May 2013 - 09:47 PM
in
Ask a Pro
Freack100, on 04 May 2013 - 05:49 PM, said:
What did you mean with "forever"?
the anti-terminate:
I hope It's helpfull for you
/>
the anti-terminate:
OldPullEvent = os.pullEvent --backup the os.pullEvent os.pullEventRaw -- override the os.pullEvent --Put this code at the top of your program --If you want to disable the anti-terminating, do this: os.pullEvent = OldPullEvent
I hope It's helpfull for you
os.pullEvent = os.pullEventRaw
As for the permanent text, just have it print and if you don't want it to stop and have it so you can type add this to the end:
while true do
sleep(60)
end
- ComputerCraft | Programmable Computers for Minecraft
- → remiX's Content


