PDA

Click to See Complete Forum and Search --> : Improve This?


ThaRubby
Jun 11th, 2005, 08:21 PM
Ok this code is working decent but needs to be improved. I tried to make it so the user cant know what his score means until he tells me it, hence the multiplying, but ill make that better later. The problem is when a user hits one answer that he knows is correct it will give him a score like 105, when he knows another one and grades it it gives him a 110. So now he sees a pattern counts the questions and wala. Can someone make it so it only grades it once? Sorry this is my first time using PHP.


<html><body>
<form method="post" action"quiz.php">

1.) <b>In order for a workstation to connect to irc.unrealircd.com, which of the following must be true?</b><br><br>

<input type="radio" value="a" name="answer1">a.) The domain irc.unrealircd.com must be set in the configuration file<br>

<input type="radio" value="b" name="answer1">b.) A Domain Name Server will resolve the domain and allow the client to connect<br>

<input type="radio" value="c" name="answer1">c.) A client will send a RARP request for the IP address<br>

<input type="radio" value="d" name="answer1">d.) A DHCP server will respond to the request<br><br>



2.) <b>Which of the following is a protocol that tests full connectivity between a client and a server (Hint: Runs over all 7 layers of the OSI model)</b><br><br>
<input type="radio" value="a" name="answer2">a.) Ping<br>
<input type="radio" value="b" name="answer2">b.) SQL<br>
<input type="radio" value="c" name="answer2">c.) Telnet<br>
<input type="radio" value="d" name="answer2">d.) DHCP<br><br>


3.) <b>Which of the following devices uses IP addresses to determine best path to a destination?</b><br><br>
<input type="radio" value="a" name="answer3">a.) A Hub<br>
<input type="radio" value="b" name="answer3">b.) A Switch<br>
<input type="radio" value="c" name="answer3">c.) ISDN<br>
<input type="radio" value="d" name="answer3">d.) A Router<br><br>

4.) <b>When setting up the IRCd, which command must be entered?</b><br><br>
<input type="radio" value="a" name="answer4">a.) ./Config<br>
<input type="radio" value="b" name="answer4">b.) ./Compile<br>
<input type="radio" value="c" name="answer4">c.) ./Make<br>
<input type="radio" value="d" name="answer4">d.) ./Install<br><br>

5.) <b>Which of the following IRCd commands will authorize a client as a network administrator?</b><br><br>
<input type="radio" value="a" name="answer5">a.) /admin<br>
<input type="radio" value="b" name="answer5">b.) /oper<br>
<input type="radio" value="c" name="answer5">c.) /oline<br>
<input type="radio" value="d" name="answer5">d.) /netadmin<br><br>

6.) <b>Which of the following commands will enable the IRCd to reload the configuration without losing host connectivity?</b><br><br>
<input type="radio" value="a" name="answer6">a.) /reload<br>
<input type="radio" value="b" name="answer6">b.) /reloadconfig<br>
<input type="radio" value="c" name="answer6">c.) /rehash<br>
<input type="radio" value="d" name="answer6">d.) /restart<br><br>

7.) <b>Which linux command will enable you to learn if the IRCd is listening on a designated port?</b><br><br>
<input type="radio" value="a" name="answer7">a.) nmap<br>
<input type="radio" value="b" name="answer7">b.) ps x<br>
<input type="radio" value="c" name="answer7">c.) ls<br>
<input type="radio" value="d" name="answer7">d.) port -a<br><br>


8.) <b>Which command in linux will specify the process id of the IRCd?</b><br><br>
<input type="radio" value="a" name="answer8">a.) ls<br>
<input type="radio" value="b" name="answer8">b.) grep<br>
<input type="radio" value="c" name="answer8">c.) chmod<br>
<input type="radio" value="d" name="answer8">d.) ps x<br><br>


9.) <b>Which linux command will change the permission of a file to read and write for both the owner and everyone else?</b><br><br>
<input type="radio" value="a" name="answer9">a.) chmod 777<br>
<input type="radio" value="b" name="answer9">b.) chmod 544<br>
<input type="radio" value="c" name="answer9">c.) chmod 666<br>
<input type="radio" value="d" name="answer9">d.) chmod 744<br><br>

10.) <b>Which commands enable a user to list the contents of a directory and remove files respectively?</b><br><br>
<input type="radio" value="a" name="answer10">a.) grep, lsmod<br>
<input type="radio" value="b" name="answer10">b.) ls, rm<br>
<input type="radio" value="c" name="answer10">c.) ps x, pico<br>
<input type="radio" value="d" name="answer10">d.) nano,kwrite<br><br>

11.) <b>Which of the following is a popular console based linux text editor?</b><br><br>
<input type="radio" value="a" name="answer11">a.) kwrite<br>
<input type="radio" value="b" name="answer11">b.) kate<br>
<input type="radio" value="c" name="answer11">c.) pico<br>
<input type="radio" value="d" name="answer11">d.) gedit<br><br>

12.) <b>Which of the following IRC Clients is not linux based and can be used to connect to an IRC server?</b><br><br>
<input type="radio" value="a" name="answer12">a.) xchat<br>
<input type="radio" value="b" name="answer12">b.) mirc<br>
<input type="radio" value="c" name="answer12">c.) irssi<br>
<input type="radio" value="d" name="answer12">d.) BitchX<br><br>
<input type="submit" value="Submit" name="submit"><br>
</form>
</body></html>


<?php
$y = 0;
$answer=$_POST["answer1"];
if ($answer == "b")
{
$y++;
}
$answer=$_POST["answer2"];
if ($answer == "c")
{
$y++;
}
$answer=$_POST["answer3"];
if ($answer == "d")
{
$y++;
}
$answer=$_POST["answer4"];
if ($answer == "a")
{
$y++;
}
$answer=$_POST["answer5"];
if ($answer == "b")
{
$y++;
}
$answer=$_POST["answer6"];
if ($answer == "c")
{
$y++;
}
$answer=$_POST["answer7"];
if ($answer == "a")
{$y = 0;
$y++;
}
$answer=$_POST["answer8"];
if ($answer == "d")
{
$y++;
}
$answer=$_POST["answer9"];
if ($answer == "c")
{
$y++;
}
$answer=$_POST["answer10"];
if ($answer == "b")
{
$y++;
}
$answer=$_POST["answer11"];
if ($answer == "c")
{
$y++;
}
$answer=$_POST["answer12"];
if ($answer == "b")
{
$y++;
}
$y = $y + 20;
$y = $y * 5;
if ($y == "100")
{
$y = "";
}
echo $y;
?>


<!--
Answers.
130 = 12/12
125 = 11/12
120 = 10/12
115 = 9/12
110 = 8/12
100 = 7/12
95 = 6/12
90 = 5/12
85 = 4/12
80 = 3/12
75 = 2/12
70 = 1/12
65 = 0/12
-->



And I have all that in quiz.php in the order its in.

ALL
Jun 11th, 2005, 08:32 PM
do you mean... you want to make sure all the answers are filled before the user's quiz is graded? could you give a link to the "almost finished" page?

ThaRubby
Jun 11th, 2005, 08:35 PM
I only want the user to be able to click submit one time, to prevent him from figuring out the answer's pattern. http://cyber-knowledge.net/~rub3x/quiz.php

ALL
Jun 11th, 2005, 08:36 PM
per session? or ever?

ThaRubby
Jun 11th, 2005, 08:39 PM
What do you consider a session? Like deleting the cookies? I would like it to go by IP address.

ALL
Jun 11th, 2005, 09:15 PM
try this:
<?php
$ips = file("ips.txt");
foreach ($ips as $ipaddies){
if($ipaddies == $_SERVER["REMOTE_ADDR"]){
exit("You have already taken this quiz!");
}
}

$handle = fopen("ips.txt", 'a+');
fwrite($handle, implode("\n", $ips) . "\n" . $_SERVER["REMOTE_ADDR"]);
fclose($handle);

$answers = array("b","c","d","a","b","c","a","d","c","b","c","b");
for ($i=1; $i<=12; $i++){
if($_POST["answer$i"] == $answers["$i"]){
$y++;
}else{
$xprint .= "#$i is $answers[$i]\n";
}
}

$y = ($y + 20) * 5;
if ($y == "100") { $y = ""; }
if(!$xprint){
echo $y;
}else{
echo $y "\nAnswers you missed, and their corrections:\n$xprint";
}
?>

ThaRubby
Jun 11th, 2005, 10:08 PM
That doesnt work. When the user loads the page, it logs the ip, therefor when they hit the button it says already toke the test.

ALL
Jun 11th, 2005, 10:25 PM
oh, simple fix...
<?php
if($_POST['submit']){
$ips = file("ips.txt");
foreach ($ips as $ipaddies){
if($ipaddies == $_SERVER["REMOTE_ADDR"]){
exit("You have already taken this quiz!");
}
}

$handle = fopen("ips.txt", 'a+');
fwrite($handle, implode("\n", $ips) . "\n" . $_SERVER["REMOTE_ADDR"]);
fclose($handle);

$answers = array("b","c","d","a","b","c","a","d","c","b","c","b");
for ($i=1; $i<=12; $i++){
if($_POST["answer$i"] == $answers["$i"]){
$y++;
}else{
$xprint .= "#$i is $answers[$i]\n";
}
}

$y = ($y + 20) * 5;
if ($y == "100") { $y = ""; }
if(!$xprint){
echo $y;
}else{
echo $y "\nAnswers you missed, and their corrections:\n$xprint";
}
}
?>

ThaRubby
Jun 11th, 2005, 10:33 PM
Not to be annoying but it still doesnt work :[ I added more questions, but I think it should still work.

<html>
<body>
<form method="post" action"quiz.php">

<p>1.) <b>In order for a workstation to connect to irc.unrealircd.com, which of the following must be true?</b><br>
<br>

<input type="radio" value="a" name="answer1">
a.) The domain irc.unrealircd.com must be set in the configuration file<br>

<input type="radio" value="b" name="answer1">
b.) A Domain Name Server will resolve the domain and allow the client to connect<br>

<input type="radio" value="c" name="answer1">
c.) A client will send a RARP request for the IP address<br>

<input type="radio" value="d" name="answer1">
d.) A DHCP server will respond to the request<br>
<br>



2.) <b>Which of the following is a protocol that tests full connectivity between a client and a server (Hint: Runs over all 7 layers of the OSI model)</b><br>
<br>
<input type="radio" value="a" name="answer2">
a.) Ping<br>
<input type="radio" value="b" name="answer2">
b.) SQL<br>
<input type="radio" value="c" name="answer2">
c.) Telnet<br>
<input type="radio" value="d" name="answer2">
d.) DHCP<br>
<br>


3.) <b>Which of the following devices uses IP addresses to determine best path to a destination?</b><br>
<br>
<input type="radio" value="a" name="answer3">
a.) A Hub<br>
<input type="radio" value="b" name="answer3">
b.) A Switch<br>
<input type="radio" value="c" name="answer3">
c.) ISDN<br>
<input type="radio" value="d" name="answer3">
d.) A Router<br>
<br>

4.) <b>When setting up the IRCd, which command must be entered?</b><br>
<br>
<input type="radio" value="a" name="answer4">
a.) ./Config<br>
<input type="radio" value="b" name="answer4">
b.) ./Compile<br>
<input type="radio" value="c" name="answer4">
c.) ./Make<br>
<input type="radio" value="d" name="answer4">
d.) ./Install<br>
<br>

5.) <b>Which of the following IRCd commands will authorize a client as a network administrator?</b><br>
<br>
<input type="radio" value="a" name="answer5">
a.) /admin<br>
<input type="radio" value="b" name="answer5">
b.) /oper<br>
<input type="radio" value="c" name="answer5">
c.) /oline<br>
<input type="radio" value="d" name="answer5">
d.) /netadmin<br>
<br>

6.) <b>Which of the following commands will enable the IRCd to reload the configuration without losing host connectivity?</b><br>
<br>
<input type="radio" value="a" name="answer6">
a.) /reload<br>
<input type="radio" value="b" name="answer6">
b.) /reloadconfig<br>
<input type="radio" value="c" name="answer6">
c.) /rehash<br>
<input type="radio" value="d" name="answer6">
d.) /restart<br>
<br>

7.) <b>Which linux command will enable you to learn if the IRCd is listening on a designated port?</b><br>
<br>
<input type="radio" value="a" name="answer7">
a.) nmap<br>
<input type="radio" value="b" name="answer7">
b.) ps x<br>
<input type="radio" value="c" name="answer7">
c.) ls<br>
<input type="radio" value="d" name="answer7">
d.) port -a<br>
<br>


8.) <b>Which command in linux will specify the process id of the IRCd?</b><br>
<br>
<input type="radio" value="a" name="answer8">
a.) ls<br>
<input type="radio" value="b" name="answer8">
b.) grep<br>
<input type="radio" value="c" name="answer8">
c.) chmod<br>
<input type="radio" value="d" name="answer8">
d.) ps x<br>
<br>


9.) <b>Which linux command will change the permission of a file to read and write for both the owner and everyone else?</b><br>
<br>
<input type="radio" value="a" name="answer9">
a.) chmod 777<br>
<input type="radio" value="b" name="answer9">
b.) chmod 544<br>
<input type="radio" value="c" name="answer9">
c.) chmod 666<br>
<input type="radio" value="d" name="answer9">
d.) chmod 744<br>
<br>

10.) <b>Which commands enable a user to list the contents of a directory and remove files respectively?</b><br>
<br>
<input type="radio" value="a" name="answer10">
a.) grep, lsmod<br>
<input type="radio" value="b" name="answer10">
b.) ls, rm<br>
<input type="radio" value="c" name="answer10">
c.) ps x, pico<br>
<input type="radio" value="d" name="answer10">
d.) nano,kwrite<br>
<br>

11.) <b>Which of the following is a popular console based linux text editor?</b><br>
<br>
<input type="radio" value="a" name="answer11">
a.) kwrite<br>
<input type="radio" value="b" name="answer11">
b.) kate<br>
<input type="radio" value="c" name="answer11">
c.) pico<br>
<input type="radio" value="d" name="answer11">
d.) gedit<br>
<br>

12.) <b>Which of the following IRC Clients is not linux based and can be used to connect to an IRC server?</b><br>
<br>
<input type="radio" value="a" name="answer12">
a.) xchat<br>
<input type="radio" value="b" name="answer12">
b.) mirc<br>
<input type="radio" value="c" name="answer12">
c.) irssi<br>
<input type="radio" value="d" name="answer12">
d.) BitchX<br>
<br>


13.) <strong>Locate the grammatical error from the following sentence.</strong></p>
<p> My colleague and myself received an award for our paper on the accuracy with which a polygraph measures physiology processes.<br>
<br>
<input type="radio" value="a" name="answer13">
a.) myself <br>
<input type="radio" value="b" name="answer13">
b.) award for <br>
<input type="radio" value="c" name="answer13">
c.) with which <br>
<input type="radio" value="d" name="answer13">
d.) measures <br>
<input type="radio" value="e" name="answer13">
e.) No Error </p>
<p>14.) <strong>Locate the grammatical error from the following sentence.</strong></p>
<p> Marathon racing, a challenging test of endurance, has become increasingly popular among amateur athletes in the last few years.<br>
<br>
<input type="radio" value="a" name="answer14">
a.) has become <br>
<input type="radio" value="b" name="answer14">
b.) increasingly popular <br>
<input type="radio" value="c" name="answer14">
c.) among <br>
<input type="radio" value="d" name="answer14">
d.) last few <br>
<input type="radio" value="e" name="answer14">
e.) No Error </p>
<p>15.) <strong>Locate the grammatical error from the following sentence.</strong></p>
<p> Although one likes to believe that your own children are beautiful, intelligent, and well behaved, what one believes is not always the case.<br>
<br>
<input type="radio" value="a" name="answer15">
a.) Although<br>
<input type="radio" value="b" name="answer15">
b.) likes to believe<br>
<input type="radio" value="c" name="answer15">
c.) your own<br>
<input type="radio" value="d" name="answer15">
d.) the case<br>
<input type="radio" value="e" name="answer15">
e.) No Error </p>
<p>16.) <strong>Locate the grammatical error from the following sentence.</strong></p>
<p> The warning in the plays is clear: unless we restore the integrity of the family, all traditional values will disappear .<br>
<br>
<input type="radio" value="a" name="answer16">
a.) is <br>
<input type="radio" value="b" name="answer16">
b.) unless <br>
<input type="radio" value="c" name="answer16">
c.) of the family<br>
<input type="radio" value="d" name="answer16">
d.) will disappear<br>
<input type="radio" value="e" name="answer16">
e.) No Error </p>
<p>17.) <strong>Locate the grammatical error from the following sentence.</strong></p>
<p> In the United States , the industrial use of plastics is greater than steel , aluminum, and copper combined.<br>
<br>
<input type="radio" value="a" name="answer17">
a.) In <br>
<input type="radio" value="b" name="answer17">
b.) use of <br>
<input type="radio" value="c" name="answer17">
c.) is <br>
<input type="radio" value="d" name="answer17">
d.) than steel <br>
<input type="radio" value="e" name="answer17">
e.) No Error </p>
<p>18.) <strong>Locate the grammatical error from the following sentence.</strong></p>
<p> The dolls in the collection, all more than two hundred years old, had been carefully carved for children long since gone.<br>
<br>
<input type="radio" value="a" name="answer18">
a.) all <br>
<input type="radio" value="b" name="answer18">
b.) more than <br>
<input type="radio" value="c" name="answer18">
c.) carefully <br>
<input type="radio" value="d" name="answer18">
d.) long since <br>
<input type="radio" value="e" name="answer18">
e.) No Error </p>
<p><br>
<input type="submit" value="Submit" name="submit">
<br>
</p>
</form>
</body>
</html>
<?php
if($_POST['submit']){
$ips = file("ips.txt");
foreach ($ips as $ipaddies){
if($ipaddies == $_SERVER["REMOTE_ADDR"]){
exit("You have already taken this quiz!");
}
}

$handle = fopen("ips.txt", 'a+');
fwrite($handle, implode("\n", $ips) . "\n" . $_SERVER["REMOTE_ADDR"]);
fclose($handle);

$answers = array("b","c","d","a","b","c","a","d","c","b","c","b","a","e","c","e","d","e");
for ($i=1; $i<=18; $i++){
if($_POST["answer$i"] == $answers["$i"]){
$y++;
}else{
$xprint .= "#$i is $answers[$i]\n";
}
}

$y = ($y + 20) * 5;
if ($y == "100") { $y = ""; }
if(!$xprint){
echo $y;
}else{
echo $y;
}
}

ALL
Jun 11th, 2005, 11:50 PM
well, i cant test it, because my laptop (with php, cgi, exc...) and i are parted for the time being.

anyway, the (best) thing to do is to have a file on the server with all the questions/answers in it.

here is what i got on it before quitting (going to bed):
<?php
if($_POST['submit']){
$ips = file("ips.txt");
foreach ($ips as $ipaddies){
if($ipaddies == $_SERVER["REMOTE_ADDR"]){
exit("You have already taken this quiz!");
}
}

$handle = fopen("ips.txt", 'a+');
fwrite($handle, implode("\n", $ips) . "\n" . $_SERVER["REMOTE_ADDR"]);
fclose($handle);

$qafile = file("questions.txt");
foreach($qafile as $num => $qs){
$qanda = split(chr(1), $qs);
if($_POST["q$num"] == $qanda[1]){
$y++;
}else{
$xprint .= "Numer $num, <i>$qanda[0]</i>'s should have been $qanda[1], $qanda[2]<br />\n";
}
}

$y = ($y + 20) * 5;
if ($y == "100") {
$y = "";
}
echo "Your score is: <i>$y</i>\n$xprint";
}
?>

well, i didnt finish this, and probably wont, but i'll give you what i got, while working on it:
<html>
<head>
<title>Add/Delete Questions</title>
</head>
<body>
<form method="POST" action="edit.php">
<table border="0" width="100%">
<td>
<?php
if($_POST['B1']){
$qandafile = file("questions.txt");
foreach ($qandafile as $num => $qsandas){
if($_POST["c$num"]){
$qandafile["$num"] = '';
}
}
foreach ($qandafile as $num => $tmp){
if ($qandafile[$num] == ''){ array_splice($qandafile, $num); }
}
$handle = fopen("questions.txt", 'a+');
fwrite($handle, implode("\n", $qandafile));
fclose($handle);
}elseif($_POST['B2']){
$qandafile = file("questions.txt");
$handle = fopen("questions.txt", 'a+');
fwrite($handle, implode("\n", $qandafile) . $_POST['T1'] . chr(1) . );
fclose($handle);
}

$qandafile = file("questions.txt");
foreach ($qandafile as $num => $qsandas){
$qanda = split(chr(1), $qsandas);
echo "<td>$qanda<input type=\"checkbox\" name=\"c$num\"></td><tr>";
}


?>
<input type="checkbox" name="C1"></td><tr>
</table>
<p><input type="submit" value="Delete" name="B1"></p>
<p>Question:<input type="text" name="T1" size="60"></p>
<p>Correct Answer: <input type="text" name="T2" size="53"></p>
<p>False answers (per line):<textarea rows="5" name="S1" cols="36"></textarea></p>
<p><input type="submit" value="ADD" name="B2"></p>
</form>
</body>
</html>
one thing i really screwed up on was in the questions.txt file, i forgot to put fake answers in, so you will need to find a way to fix that in both php files, if you want to use it like this!

ThaRubby
Jun 12th, 2005, 01:36 AM
one thing i really screwed up on was in the questions.txt file, i forgot to put fake answers in, so you will need to find a way to fix that in both php files, if you want to use it like this!


Yea, this is my first PHP experiece :blush: Anyone else want to take a shot? Also I have ftp and shell access if you know some basic linux commands :)...You could use pico (editor)