Welcome to WebmasterWorld Guest from 126.96.36.199
($_SERVER['REQUEST_METHOD'] == "POST" && $_POST[variable] && $_POST[variable] == $_SESSION[variable])
$rand = rand(0,4);
$_SESSION[variable] = $rand;
With thanks in advance
With this in mind... I don't see how you can 100% exactly replicate your code into Java because there are some fundamental differences.
Your code is conditional on:
(a) request type is post;
(b) post variable 'variable' exists (?); and
(c) post variable 'variable' equals the value of 'variable' in SESSION
If this occurs, your code then create a random integer (0 to 4) and sets this to the session variable, then displays the value.
Considering just this logic, you can recreate the idea in Java. I haven't coded Java in awhile, so I do not recall the exact notations/syntax, but here's what you got to do:
It looks like you are trying to compare a "posted or given value" against a value "stored in memory". All you need to do is get the value you want from the user. You can do this by creating a dialog requesting user input [ex: store it as something 'userinput']. You can then return this input to a method that checks if the entered value matches a predefined value. You'll want to create a global/class variable that holds the defining value [ex: call it 'setting']. This method can then check if the returning 'userinput' matches the 'setting'. If it does, then you go through the process of updating the value of 'setting' with a new random integer (Java has such functionality built into its math library I believe). You can then also display this new value at this point. However, if they do not match... you could then alert the user that the values do not match, and even restart the process by recalling the dialog for input.
Hope that makes sense. I'm sure you were looking for the code to copy/paste, but that isn't always my style... perhaps my thoughts can help you figure out how to get your "idea" working in Java. :)
Regardless... What you are doing in your code seems ambiguous and like a quasi-validation attempt. I am curious as to what/why/how you are doing this.
Note my experience with Java is in standalone, compiled applications. Though I suppose some sites may be using a Java backend, I am not familiar with this.