Skip to main content
gamedev.net
🔒 Locked

[web] My first PHP

Started by mrtie_dye 7 replies 1.1k views
Original Post
mrtie_dye
mrtie_dye
Thanks guys for all your help on my first PHP project ever! It is nothing all that grand. Just a simple "Petals Around the Rose" game. Check it out here , test it out, and let me know what you think. Thanks so much!
Marriage is the #1 cause of divorce
Drew_Benton
Drew_Benton
Nice! But you can 'cheat' by submiting an answer and hitting 'back' [wink]. You might want to fix that.
Pipo DeClown
Pipo DeClown
LOL! I don't konw how it works.. Funny though.
Kippesoep
Kippesoep
It's such a "Doh!" moment when you figure it out :)
Kippesoep
choffstein
choffstein
You can cheat even easier than that. Just look at the page source. Example:
<form action="rose.php" method="post"> 	Please enter answer here: <input type="text" name="guess"> 	<input type="hidden" name="answer" value="10">	<input type="hidden" name="score" value="1"> 	<input type="submit" name="submit" value="Submit" /></form>


Herm....I think I see the answer there. Other than that, its pretty well done!
mrtie_dye
mrtie_dye
Quote:

It's such a "Doh!" moment when you figure it out :)


Yes, it really is! It took me about 2 hours to finally figure it out, and when I did, I could have kicked myself!

Quote:
You can cheat even easier than that. Just look at the page source. Herm....I think I see the answer there. Other than that, its pretty well done!


Well, that doesn't really matter, because the object of the game is to figure out how I got that answer, not the answer itself. Yes, you might be able to get a perfect score by doing it that way, but that will not teach you how to get the answer. Which is the whole point.


Quote:

Nice! But you can 'cheat' by submiting an answer and hitting 'back' . You might want to fix that.


Not really sure what you mean by this. How does hitting back help you? Read the comments above about the object of the game. Do you still consider this a cheat? If so, please explain how hitting back can help you.

Thanks all for your comments. Although I don't think either issue brought up could really be considered cheating, I would like to fix them, if possible. Any suggestions?

[Edited by - mrtie_dye on March 20, 2005 3:01:03 PM]
Marriage is the #1 cause of divorce
mrtie_dye
mrtie_dye
Here is the full source, minus the parts that would give away the secret. :) Also note that index.php is an exact copy of rose.php, except that index.php does not use DisplayAnswer($answer, $guess, &$score) and it sends the score to rose.php as 0.

<html><title>Petals Around The Rose</title><?phpfunction make_seed(){   list($usec, $sec) = explode(' ', microtime());   return (float) $sec + ((float) $usec * 100000);}function DisplayRules(){	?>	<p align="center"><font size=15 color="red">Petals Around The Rose</font></p>	<p>There are only three things I can tell you about this game.</p>	<p>1. I can tell you the name of the game is Petals Around The Rose and that name is significant.</p>	<p>2. I can tell you the answer is always either zero or an even number</p>	<p>3. I can tell you the answer.	<p>Please enter your guess below. Once you get six in a row correct, it will be obvious that you know the secret tothis game. The true answer will be given after you enter your guess. Thanks for playing!</p>	<?php}function RollDice(&$answer, $diceside){	$diceside = array(1 => rand(1,6), 2 => rand(1,6), 3 => rand(1,6), 4 => rand(1,6), 5 => rand(1,6));	for ($i = 1; $i <= 5; $i++) 	{		if($diceside[$i] == 1)		{			?>			<img src="green1.gif">			<?php		}		elseif($diceside[$i] == 2)		{			?>			<img src="green2.gif">			<?php		}		elseif($diceside[$i] == 3)		{			?>			<img src="green3.gif">			<?php		}		elseif($diceside[$i] == 4)		{			?>			<img src="green4.gif">			<?php		}		elseif($diceside[$i] == 5)		{			?>			<img src="green5.gif">			<?php		}		elseif($diceside[$i] == 6)		{			?>			<img src="green6.gif">			<?php		}	}}function DisplayAnswer($answer, $guess, &$score){	if($score >= 5 && $answer == $guess) 	{		$score++;		?>		<p> You have gotten <?php echo $score ?> in a row correct. Congratulations! You have figured out the mystery of Petals Around The Rose! Be sure to keep it a secret. Let everyone else figure it out for themselves! Thanks so much for playing!!!</p> 		<?php	}	else	{		if($answer == $guess)		{			$score++;			?>			<p>You are correct! The answer was <?php echo $answer ?> You have gotten <?php echo $score ?> correct so far!</p>			<?php					}		else		{			?>			<p>Sorry! You were not correct. The correct answer was <?php echo $answer ?> </p>			<?php			$score = 0;		}	}}srand(make_seed());$randval = rand();DisplayRules();DisplayAnswer($answer, $guess, &$score);$answer = 0;RollDice(&$answer, $diceside);$guess = 0;?><form action="rose.php" method="post"> 	<p>Please enter answer here: <input type="text" name="guess"></p> 	<input type="hidden" name="answer" value="<?php echo $answer; ?>">	<input type="hidden" name="score" value="<?php echo $score; ?>"> 	<p><input type="submit" name="submit" value="Submit" /></p></form><br><br><p align=center><font size=2>I first learned about this riddle <a href="http://www.borrett.id.au/computing/petals-bg.htm" target=new>here</a>. I sort of borrowed their graphics for testing, but will be changing them as soon as I get a chance to make some. Thanks to <a href="http://www.borrett.id.au/computing/petals-bg.htm" target=new>Lloyd Borrett</a> for the inspiration to write my first php program.</font></p></html>


[Edited by - mrtie_dye on March 20, 2005 3:04:33 PM]
Marriage is the #1 cause of divorce
mrtie_dye
mrtie_dye
I appologize to anyone who tried to figure this riddle out in the past hour or so on my web page. I was making some changes and messed a few things up pretty bad. It appears to be working again. Again, I appologize. I hope you enjoy it, now that it is fixed, again.
Marriage is the #1 cause of divorce
kango19
kango19
whoa, nice game :) took me 20 minutes to solve this, but that was just because I remembered I had solved this riddle before.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.