To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Coding

Coding Help with PHP coding

Reply
 
Thread Tools Rate Thread Display Modes
Old 03-19-2005, 09:55 PM   #1
Terran
Junior Member
 
Join Date: Mar 2005
Posts: 17
Guessing Game

Well I had a guessing game in mind and I figured I'd do this:
  • Generate a random number once.
  • Assign it to a variable.
  • Get input from a user via form.
  • Store this input in a variable and check it vs the random number.
  • Have a final variable that holds which "Guess Number" it is (how many guesses the user has made thus far).

However, I just ran into a problem that stumped me. How can I pass this information on throughout the game? I originally planned to do it like this:

You go to the game file and make a guess. If you are wrong, the file increments the "Guess Number" variable and sends both the "Guess Number" value and the "Magic Number" value to itself, using this as a way to keep the numbers consistent.

However, it just occured to me that the user will be able to see the "Magic Number" in the URL then.

Therefore, I do not know how to pass the number and the guess number on through multiple steps.

Can someone please enlighten me? Thanks.

Code I wrote so far:

PHP Code:
<?php

$guess
= $_POST['guess'];
$number = rand(1,100);
$guessnumber = $_GET['guessnumber'];

echo
"<H1> Guess #$guessnumber</H1>";

if(
$guess == $number){
    echo
'<BR>';
    echo
'You win!!!';
    echo
"You took $guessnumber guesses.";
}else{
    
$guessnumber++;
    echo
"<A HREF=\"http://localhost/guessgame.php?guessnumber=$guessnumber\">Keep on guessing!</A>";
}
?>
Terran is offline   Reply With Quote
Old 03-19-2005, 10:09 PM   #2
drew010
Senior Member
 
drew010's Avatar
 
Join Date: Apr 2003
Location: Santa Rosa, CA
Posts: 2,835
either using sessions or storing it in a file would be the only way to prevent them from seeing it. using sessions will be the faster and easier way to do it however.
drew010 is offline   Reply With Quote
Old 03-20-2005, 10:54 PM   #3
Terran
Junior Member
 
Join Date: Mar 2005
Posts: 17
Oh. Thanks for the information.
Terran is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 08:30 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.