Show DevBest [PHP] Simple PHP game ! [Mac]

Status
Not open for further replies.

Mac

New Member
Feb 9, 2011
111
2
PHP:
<?php 
/* A simple PHP game programmed by Mac */ 
$game = array(); 
$game["number"] = $_GET["number"]; 
$game["add"] = $_GET["add"]; # You can change this number ! 
$game["result"] = $game["add"] / 2; 
if($_GET["submit"]): 
    if($game["number"] and $game["add"]): 
        if(is_numeric($game["number"]) and is_numeric($game["add"])):
            echo "<p>Your number is {$game["number"]}</p>"; 
            echo "<p>Multiple your number 2 times and then do plus {$game["add"]} and then divide it 2 times and do minus the number you thought ({$game["number"]}). Your result is {$game["result"]}.</p>"; 
        else:
            echo "Number and random number are not numeric!";
        endif;
    else: 
        echo "Number and random number are not set"; 
    endif; 
else: 
?> 
    <form method="get"> 
        My number will be: <input type="number" name="number"> <br /> 
        Write a random number: <input type="number" name="add"> <br /> 
        <input type="submit" name="submit" value="Go!"> 
    </form> 
<?php 
endif; 
?>

I don't know how to explain it , so test and check it your self !

Credits goes to me!

Thanks!
 

X1M!

le troller
Jan 6, 2011
179
1
Uhh.. Yuck? Your not checking so that the $_GET is a number, and using the "and" operator instead of && is just ugly. I like how your using the if syntaxes, just like me. :)
 

Mac

New Member
Feb 9, 2011
111
2
X1M! i haven't done the thing to check if $_GET is numeric because the in the input you cannot put text ! So the $_GET is obv numeric . That's why !

And yeah thanks!
 

X1M!

le troller
Jan 6, 2011
179
1
You can put text in the $_GET, the $_GET is just like a normal string.
 

Mac

New Member
Feb 9, 2011
111
2
In the input , nah you can't!
The user won't set $_GET his self . In the form the $_GET can't be text! the input type is numeric!
 

X1M!

le troller
Jan 6, 2011
179
1
I like your usertitle; "Newbie".

No, seriously, the $_GET can be edited in the URL. Like , they can easily edit the value, and if the HTML form prevents inputs, a realtime editor like Firebug can edit it to allow string inputs.
 

Mac

New Member
Feb 9, 2011
111
2
ehmm! What am i saying ? OBV it can , but users are not going to set the number that way! It will be with a form , in the form they can't enter a text ! Look at the code before saying "newbie" no offence .
and yeah , who is going to use firebug and other things for this thing ? LOL!
 

X1M!

le troller
Jan 6, 2011
179
1
Learn to write proper English before writing. You dont understand the PHP -> HTML concept, PHP controls HTML, not the other way around, you have to make sure that the $_GET variable is a integer before making math operations.
 

Mac

New Member
Feb 9, 2011
111
2
Actually you don't understand it! It works with FORM ! UNDERSTOOD ? We don't need to check if get is numeric if the input in the form should be numeric ! :mad:
and yeah , ill make the code :
PHP:
<?php 
/* A simple PHP game programmed by Mac */ 
$game = array(); 
$game["number"] = $_GET["number"]; 
$game["add"] = $_GET["add"]; # You can change this number ! 
$game["result"] = $game["add"] / 2; 
if($_GET["submit"]): 
    if($game["number"] and $game["add"]): 
		if(is_numeric($game["number"]) and is_numeric($game["add"])):
			echo "<p>Your number is {$game["number"]}</p>"; 
			echo "<p>Multiple your number 2 times and then do plus {$game["add"]} and then divide it 2 times and do minus the number you thought ({$game["number"]}). Your result is {$game["result"]}.</p>"; 
		else:
			echo "Number and random number are not numeric!";
		endif;
    else: 
        echo "Number and random number are not set"; 
    endif; 
else: 
?> 
    <form method="get"> 
        My number will be: <input type="number" name="number"> <br /> 
        Write a random number: <input type="number" name="add"> <br /> 
        <input type="submit" name="submit" value="Go!"> 
    </form> 
<?php 
endif; 
?>
Are you happy now ?!!!
 

X1M!

le troller
Jan 6, 2011
179
1
Yes, but the form can be edited with a realtime editor like firebug so they change the number to text. Why dont you fucking understand?
 

Mac

New Member
Feb 9, 2011
111
2
Okay ! I added the check thing , now it's done , thank you for support!
 
Status
Not open for further replies.

Users who are viewing this thread

☀️  Switch to Light Theme

Latest posts

Top