Jump to content

  • Log In with Google      Sign In   
  • Create Account

Bad php code


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 philipborg   Members   -  Reputation: 331

Like
0Likes
Like

Posted 07 September 2012 - 10:38 AM

Hello

I am very new to PHP development and I am currently learning java and php at the same time with integration and I therefor mix them together with the syntax and so. This current code is meant to use an passed in arguments using $_GET and then process them. The current solution is just for temporal development focusing on the client java side. The problem is that not even my temporary solution is working and my IDE does not tell me any errors. I think I messed up with the scope but I am not sure.

[source lang="php"]//Set mode$error = NULL;$output = NULL;try{ $mode = $_GET["mode"];}catch(exception $exc){ $error = "No mode";} //set error to null, results in message to error if set to true//Check to make sure it is an valid userif ($mode == "userVerify"){ if (username == "open"){ $output = "valid"; }else{ try{ $username = $_GET["username"]; $password = $_GET["password"]; }catch(exception $exc){ $error = "No username or password given"; } $output = "valid"; }}//Connection checking, allways returns true if executedelseif ($mode == "connectionCheck"){ $output = "true";}//Check prestige levelelseif ($mode == "userPrestigeLevel"){ $username = $_GET["username"]; if (username == "open"){ $output = "0"; }else{ //Executed if it is not an open user $output = "0"; }}else{$error = "Unvalid mode" . $mode;}if ($output == NULL){ $error = "No output";}if ($error != NULL){ $output = "ERROR: " . $error;}echo $output;[/source]

I pass in arguments using the sytem localhost/file.php?mode=userVerify?username=test?password=test and all I receive back is "ERROR: No output". I know this code is anything but pretty, but for know all i want is some basic functionality.

Edited by philipborg, 07 September 2012 - 10:38 AM.


Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 8195

Like
2Likes
Like

Posted 07 September 2012 - 10:54 AM

The parameter list in a page request starts with ?, but parameters are separated by & and not ?.

Edited by Brother Bob, 07 September 2012 - 10:55 AM.


#3 philipborg   Members   -  Reputation: 331

Like
0Likes
Like

Posted 07 September 2012 - 10:56 AM

Ahh thanks :)

#4 demonkoryu   Members   -  Reputation: 976

Like
0Likes
Like

Posted 27 September 2012 - 01:58 AM

Also, accessing non-existing array indices doesn't throw an exception. You should check for existence of these parameters by using isset().

[source lang="php"]if (isset($_GET['mode']) { $mode = $_GET['mode'];} else { $error = "Required param 'mode' is not set.";}[/source]

Edited by demonkoryu, 27 September 2012 - 02:01 AM.


#5 slayemin   Members   -  Reputation: 2559

Like
0Likes
Like

Posted 27 September 2012 - 07:33 AM

You might also be interested in using $_SESSION and $_POST variables to store your data.

Eric Nevala

Indie Developer | Dev blog


#6 slicer4ever   Crossbones+   -  Reputation: 3886

Like
1Likes
Like

Posted 28 September 2012 - 12:38 AM

just tossing this out their(you might be already planning this, I don't know), but ontop of using POST to pass variables, i'd recommend hashing the password on the client side, before submitting it to your server, again you might have this already in mind, but just making sure is all=-)
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#7 philipborg   Members   -  Reputation: 331

Like
0Likes
Like

Posted 07 November 2012 - 01:58 PM

Thanks for all support and yes, client hashing will be ;)




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS