Post here is you are having problems with any of the tutorials.
-
phpkid01
- Posts: 9
- Joined: Wed Jul 13, 2011 4:37 pm
Post
by phpkid01 »
hey guys...
i have a question... you know the errors parameters in the JSON well its encoded in another array...
i was wondering how you decode that array aswell... to show the independant error messages as im kinda stuck...
init.inc.php:
session_start();
$login = surfcms::validate_credentials($_POST['username'], $_POST['password'], $_POST['key']);
$session = $login['session'];
$username = $login['username'];
$errors = $login['errors'];
if($session==1){
$_SESSION['site'] = "scms_" . $username;
}else{
echo $errors;
}
Cheers
-
jacek
- Site Admin
- Posts: 3262
- Joined: Thu May 05, 2011 1:45 pm
- Location: UK
-
Contact:
Post
by jacek »
You can use [url=http://php.netjson_decode/json_decode]json_decode[/url], just pass it the encoded string and you will get the original array back.
-
phpkid01
- Posts: 9
- Joined: Wed Jul 13, 2011 4:37 pm
Post
by phpkid01 »
so i should use:
session_start();
$login = surfcms::validate_credentials($_POST['username'], $_POST['password'], $_POST['key']);
$session = $login['session'];
$username = $login['username'];
$errors = json_decode($login['errors']);
if($session==1){
$_SESSION['site'] = "scms_" . $username;
}else{
foreach($errors as $error){
echo $error;
}
}
-
jacek
- Site Admin
- Posts: 3262
- Joined: Thu May 05, 2011 1:45 pm
- Location: UK
-
Contact:
Post
by jacek »
No, the function handles the decoding, you just use the result.
You should just be able to use $login['errors'] directly.
-
phpkid01
- Posts: 9
- Joined: Wed Jul 13, 2011 4:37 pm
Post
by phpkid01 »
it only returns "Array" as the result... :/
-
jacek
- Site Admin
- Posts: 3262
- Joined: Thu May 05, 2011 1:45 pm
- Location: UK
-
Contact:
Post
by jacek »
phpkid01 wrote:it only returns "Array" as the result... :/
you can't just echo an array. try doing a print_r($something) to see the format of the data you are getting.