Mikuch
/home/mikuch
First we need to one pool to table account
execute that in phpmyadnmin.
Make config file named config.php
Main file called index.php
and test file called main.php
All credits goes to me
TODO:
-More user friendly script
-More configurable config.php
-Layoute
execute that in phpmyadnmin.
Code:
ALTER TABLE accounts ADD testdate DOUBLE DEFAULT NULL;
Make config file named config.php
PHP:
<?
$host="localhost"; // Hostname.
$db_user=""; // Mysql user name.
$db_password=""; // Mysql user password.
$database=""; // Database name
$localdate = gmDate("Ymd");
$days = 7; // After how many days test can be done again
?>
Main file called index.php
PHP:
<?
session_start();
session_destroy();
$message="You are logged out"; // Message when logged out
// Login section
$login=$_POST['login'];
if($login) {
// When You click button
$name=$_POST['name'];
$password=$_POST['password'];
include('config.php');
mysql_connect($host,$db_user,$db_password);
mysql_select_db($database);
$data = mysql_query("SELECT * FROM accounts WHERE name='$name'") or die('Error');
$r = mysql_fetch_assoc($data);
$dateoftest = "".$r['testdate']."";
$checkingdays = $dateoftest - $localdate;
// Checking user name and password.
$rezultat=mysql_query("select * FROM accounts WHERE name='$name' AND password='$password'");
if(@mysql_num_rows($rezultat)){
if ($checkingdays <= -($days)){
session_register("name"); // Remember sesion name.
header("location:main.php"); // Redirect to main.php
exit;
}else {
echo "You were making test $checkingdays days ago. You have to wait $days days to try again"; // Message if You was making test less days then in written at conmfig.php
}
}else {
$message="<br>Wrong password or username"; // Message if password or username is wrong
}
} // End of authorization checking
?>
<head>
<html>
<title>Mikuch RPG - tutor test</title>
</head>
<body>
<? echo $message; ?>
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<table>
<tr>
<td>Account Name: </td>
<td><input name="name" type="text" id="name" /></td>
</tr>
<tr>
<td>Password: </td>
<td><input name="password" type="password" id="password" /></td>
</tr>
</table>
<input name="login" type="submit" id="login" value="login" />
</form>
</body>
</html>
and test file called main.php
PHP:
<?
include('config.php');
mysql_connect($host,$db_user,$db_password);
mysql_select_db($database);
session_start(); // Session declaration
if(!session_is_registered("name") ){ // Checking session name
header("location:index.php"); // Redirect to index.php
}
$name = $_SESSION['name'];
$localdate = gmDate("Ymd");
echo("Welcome "); echo $_SESSION['name']; echo("! You are logged in");
?>
<html>
<head>
<title>Mikuch RPG - Tutor test</title>
</head>
<body>
<br>Dont use capital letters in the test<br><br>
<form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>">
<table>
<!--First questiion -->
<tr>
<td>
1. first question<br>
</td>
<tr>
<td>
<input name="p1" type="text" id="p1" />
</td>
</tr>
</tr>
<!--Second question -->
<tr>
<td>
2. second question <br>
</td>
<tr>
<td>
<input name="p2" type="text" id="p2" />
</td>
</tr>
</tr>
<tr>
<td>
3. third question<br>
</td>
<tr>
<td>
<input type=radio name="p3" value="tak">Tak<br>
<input name="p3" type=radio value="nie">Nie<br>
</td>
</tr>
</tr>
<tr>
<td>
4. fourth question <br>
</td>
<tr>
<td>
<input type=radio name="p4" value="theforgottenserver">theforgottenserver<br>
<input type=radio name="p4" value="evolution">Evolution<br>
<input name="p4" type=radio value="inny">Inny<br>
</td>
<tr>
<td>
5. fifth question
</td>
<tr>
<td>
<input name="p5" type="text" id="p5" />
</td>
</tr>
</tr>
<!--Nick to become tutor -->
<tr>
<td>
Enter nick of player that will be tutor
</td>
<tr>
<td>
<input name="nick" type="text" id="nick" />
</td>
</tr>
</tr>
</table>
<?
$nick=$_POST['nick'];
$result = mysql_query("UPDATE players SET group_id='2' WHERE name='$nick'") or die(mysql_error());
?>
<input name="answer" type="submit" id="answer" value="answer" />
</form>
<?
$odpowiedz=$_POST['odpowiedz'];
if($answer)
{
$p1=$_POST['p1'];
$p2=$_POST['p2'];
$p3=$_POST['p3'];
$p4=$_POST['p4'];
$p5=$_POST['p5'];
$localdate = gmDate("Ymd");
echo('You answers:<br>');
echo("1. $p1<br>");
echo("2. $p2<br>");
echo("3. $p3<br>");
echo("4. $p4<br>");
echo("5. $p5<br>");
$data = mysql_query("SELECT * FROM accounts WHERE name='$name'") or die('Bł±d zapytania');
$r = mysql_fetch_assoc($data);
$datatestu = "".$r['testdate']."";
$sprawdzenie = $datatestu - $localdate;
if($p1=='first answer' && $p2=='second answer' && $p3=='third answer' && $p4 =='fourth answer' && $p5=='fifth answrr' && $sprawdzenie <= -($days))
{
echo('<font size="5">You made it!!! all answers are correct.</font><br>');
$nick=$_POST['nick'];
$result = mysql_query("UPDATE players SET group_id='2' WHERE name='$nick'") or die(mysql_error());
$result3 = mysql_query("UPDATE accounts SET testdate='$localdate' WHERE name='$name'") or die(mysql_error());
}
else
{
echo('You did not passed exam try again after $days.');
$result3 = mysql_query("UPDATE accounts SET testdate='$localdate' WHERE name='$name'") or die(mysql_error());
?>
<meta http-equiv="Refresh" content="0; URL=index.php"; />
<?
}
}
?>
<p><a href="index.php">Log out</a></p>
</body>
</html>
All credits goes to me
TODO:
-More user friendly script
-More configurable config.php
-Layoute
Last edited by a moderator: