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 user
if ($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 executed
elseif ($mode == "connectionCheck"){
$output = "true";
}
//Check prestige level
elseif ($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.
Bad php code
The parameter list in a page request starts with ?, but parameters are separated by & and not ?.
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]
[source lang="php"]
if (isset($_GET['mode']) {
$mode = $_GET['mode'];
} else {
$error = "Required param 'mode' is not set.";
}
[/source]
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=-)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement