Clanz Darkness
Dołączył: 29 Mar 2006
Posty: 11
Przeczytał: 0 tematów
Ostrzeżeń: 0/5
Skąd: Oracle
|
Wysłany: Śro 21:26, 29 Mar 2006 Temat postu: Test na Tutora - skrypt do acc makerów |
|
|
|
Polega on na tym, że na swojej stronie/acc makerze mozesz umiescic test na tutora, w którym mozesz napisać swoje pytania
tutor_test.php:
Kod: | <?php
// Fetch the question set for the tutor test
require('tutor_questions.php');
// Database information - Non of this information is sent from your computer
$database_host = 'localhost';
$database_user = '';
$database_password = '';
$database_name = 'tutor_test';
// The name of the table in your database that holds the player's ip and timestamp
$table_name = 'players';
// Days to wait before they are allowed to take the test again
$days_to_wait = 10;
// The number of questions they have to get correct to pass
$pass_number = 10;
// The path to your accounts folder and players folder
$account_folder = 'C:\OTS\data\accounts/'; // Remember to put the forward slash at the end!
$players_folder = 'C:\OTS\data\players/'; // Remember to put the forward slash at the end!
// Connect to the database to retrieve player ip and timestamp (if they have taken the test before)
mysql_connect($database_host, $database_user, $database_password);
mysql_select_db($database_name);
// Convert days to wait to unix timestamp
$days_to_wait = $days_to_wait * 86400;
// Assign questions and answers to array for display purposes
foreach ($question as $thequestion)
{
$questions[] = $thequestion;
}
foreach ($answer as $theanswer)
{
$answers[] = base64_encode($theanswer);
}
// Assign entered account and pass to variables
$account = $_POST['account'];
$password = $_POST['password'];
if (isset($_POST['login']))
{
if (!empty($account) && !empty($password))
{
// Assign file to variable and check if it exists
$file = $account_folder . $account . '.xml';
if (file_exists($file))
{
if (is_readable($file))
{
$open_file = fopen($file, "r");
$contents = fread($open_file, filesize($file));
$tags = explode("<", $contents);
$number = 0;
$char_array = array();
// Run through the tags to the password tag to match entered password
foreach ($tags as $tag)
{
if (substr($tag, 0, 7) == "account")
{
if ($temp_pass = stristr($tag, "pass=\""))
{
$temp = explode("\"", $temp_pass);
$pass = $temp[1];
}
}
// Run through the tags to get the name of the characters
if (substr($tag, 0, 9) == "character")
{
if ($temp_name = stristr($tag, 'name="'))
{
$temp_name = explode('"', $temp_name);
$name = $temp_name[1];
$char_array[$number] = $name;
$number++;
}
}
}
// Check if the player failed the tutor test recently
$query = mysql_query('SELECT ip, timestamp FROM '.$table_name.' WHERE (ip = "'.$_SERVER['REMOTE_ADDR'].'") AND (timestamp > '.time().')') or die(mysql_error());
$player_info = mysql_fetch_assoc($query);
if (mysql_num_rows($query) > 0)
{
echo 'Sorry, you must wait ' . date('j',($player_info['timestamp'] - time())) .' days before you can take the tutor test again.';
}
else
{
// Check that entered password matches pass in account file
if ($pass == $password)
{
?>
<form action="tutor_test.php" method="POST">
<table>
<tr>
<td><h2>Tutor Test</h2></td>
</tr>
<tr>
<td>Which character would you like to take the tutor test with?</td>
</tr>
<tr>
<td>
<select name="name">
<?php
$i = 0;
while (!empty($char_array[$i]))
{
echo '<option>' . $char_array[$i] . '</option>';
$i++;
}
?>
</select>
</td>
</tr>
<tr>
<td> </td>
</tr>
<?php $q = 1; ?>
<?php foreach ($questions as $question): ?>
<tr>
<td><?php echo $q . '.' . $question; ?> ?</td>
</tr>
<tr>
<td><input name="user_answers[<?php echo $q; ?>]" type="text" /></td>
</tr>
<tr><td><?php $q++; ?> </td></tr>
<?php endforeach; ?>
<tr>
<td><input type="submit" name="submit" value="Mark my test" /></td>
</tr>
</table>
</form>
<?php
}
else
{
// User entered password does not match the password in the file
echo 'The password you entered is incorrect.<br />';
echo '<a href="tutor_test.php">Try again</a>';
}
}
}
else
{
// The file could not be read
echo 'The file could not be read.<br />';
echo '<a href="tutor_test.php">Try again</a>';
}
}
else
{
// The account file could not be found
echo 'The account you have specified does not exist. <br />';
echo '<a href="tutor_test.php">Try again</a>';
}
}
else
{
// The user left one or more textboxes empty
echo 'You must enter both an account number and a password. <br />';
echo '<a href="tutor_test.php">Try again</a>';
}
}
else
{
// Has the user requested that their answers be marked?
if (isset($_POST['submit']))
{
$j = 0;
$name = $_POST['name'];
$correct_answers = 0;
// Loop through user supplied answers and see if they match the the answer from the question file
foreach ($_POST['user_answers'] as $answer)
{
if ($answer == base64_decode($answers[$j]))
{
$correct_answers++;
}
$j++;
}
// Display the users score for the test
echo 'Your score was ' . $correct_answers . '.';
// Check if the user got enough marks to pass
if ($correct_answers >= $pass_number)
{
echo '<br><br>You <strong>passed</strong> the tutor test.';
// Change the user's access level to 1 (tutor)
$player_file = $players_folder . $name . '.xml';
if (file_exists($player_file))
{
$open_file = fopen($player_file, 'r');
$playerXML = simplexml_load_string(fread($open_file, 999999));
fclose($open_file);
$dom = dom_import_simplexml($playerXML);
$dom->setAttribute('access', 1);
$newplayerFile = $playerXML->asXML();
$open_file = fopen($player_file, 'w');
fwrite($open_file, $newplayerFile);
fclose($open_file);
}
}
else
{
// The user did not get enough questions correct
echo '<br><br>Sorry, you did <strong>not</strong> pass the test';
}
// Save the user's ip address in the database so that they cannot retake the test straight away
mysql_query('INSERT INTO players
SET ip = "'.$_SERVER['REMOTE_ADDR'].'",
timestamp = '.(time() + $days_to_wait).'');
}
else
{
?>
<form action="tutor_test.php" method="POST">
<table>
<tr>
<td colspan="2"><h3>Log in to take the tutor test</h3></td>
</tr>
<tr>
<td>Account: </td>
<td><input name="account" type="text" /></td>
</tr>
<tr>
<td>Password: </td>
<td><input name="password" type="password" /></td>
</tr>
<tr>
<td colspan="2"><input name="login" type="submit" value="Log in" /></td>
</tr>
</table>
</form>
<?php
}
}
?> |
tutor_questions.php: (pytania)
Kod: | <?php
// Create arrays for questions and answers
$questions = array();
$answers = array();
$question[1] = 'What is the number of unjust kills a player can have before they get a red skull';
$question[2] = 'What is my name';
$answer[1] = '6';
$answer[2] = 'Kreator';
?> |
baza sql:
Kod: | CREATE TABLE `players` (
`id` int(11) NOT NULL auto_increment,
`timestamp` int(25) NOT NULL default '0',
`ip` varchar(25) NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; |
Jesli nastapily jakis bledy - pisz
-------------------------------------------------------------------
Zastrzegam sobie prawa autorskie. Jeśli ktoś bedzie chciał na podstawie tego skryptu napisac taki drugi albo zkorzystać chociarz z cześci proszę napisać priv wiadomość.
Post został pochwalony 0 razy |
|
|