Skip to main content
GameDev.net gamedev.net
🔒 Locked 🤖 Godot

[web] php question

Started by mrtie_dye Mar 19, 2005 at 10:32 PM 3 replies 500+ views
Original Post
mrtie_dye
mrtie_dye
I am brand new to php, and figured I would start with a simple "Petals Around the Rose" game. For those of you not familiar with this riddle, you can check it out here . Anyway, here is what I have so far, minus the parts that would give away the answer to the riddle. greenX.gif is a picture of a green die displaying the number represented by X. In other words, green5.gif would be a picture of a green die showing 5 dots.

<?php
function make_seed()
{
   list($usec, $sec) = explode(' ', microtime());
   return (float) $sec + ((float) $usec * 100000);
}
srand(make_seed());
$randval = rand();

$answer = 0;

$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
	}

}
?>



Ok, at some point, it calculates the answer, and stores it in, can you guess? That's right, $answer. Now, I want to give the user a nice little text box they can type in their guess, hit submit, and have php compare $guess with $answer, and tell them if they are right or wrong. But I am not sure how to go about this. I understand how to make the text box, and how to submit what is in the text box($guess) to another php page, but how do I send $answer? Thanks for any help you can provide. [Edited by - mrtie_dye on March 20, 2005 4:30:17 PM]
Marriage is the #1 cause of divorce
Deranged
Deranged
encrypt it, pass it to the url using page.php?ans=encrypted data, decrypt it in that second page.

PS: PHP has many encryption functions, check the docs, and im sure you know how to use $_POST to grab the answer from the url.
mrtie_dye
mrtie_dye
Thanks for the fast response, but I think I should mention again in all caps I AM BRAND NEW TO PHP. The only way I have gotten this far is some c and c++ expirence. I have no idea how to encrypt things, and barely understand forms. Please take it easy on me. Sesame Street level please. :)
Marriage is the #1 cause of divorce
Colin Jeanne
Colin Jeanne
One way to do this that avoids encryption is to create a hidden textbox in your form. You can make one by using the input tag with type set to "hidden". When PHP outputs the page output $answer into the value of the hidden box, like so:



Now, when the submit button is pressed your answer is submitted along with your guess. You'll access data submitted from your hidden textbox the same way as you access data from your visible one.
mrtie_dye
mrtie_dye
Thanks invader, that was exactly what I was looking for. In hindsight, I should have explained that it does not matter if the user knows the answer once they push sumbit. I am going to give it to them on the next page anyway. That is how the game works. I was tired last night when I read DerAnged's post, and did not even think about why he was suggesting encryption. Thanks for both your replys!
Marriage is the #1 cause of divorce

Topic Locked

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

Sign in to reply to this topic.