0

I am not a php guy, so I have a small question for all the php devs out there.

I am building a java application which calls a php webservice. The php web service has a login method which takes user_auth and application_name as parameters. user_auth is an array which has three strings username, password and version number.

Can anyone tell me which of the below java strings match the array output when we print it?

1) String user = "user_auth{username=will; password=18218139eec55d83cf82679934e5cd75; version=1.0;}";
2) String user = "{'user_auth':{'username':'will','password':'18218139eec55d83cf82679934e5cd75', 'version':'1.0'}}";

Thanks, aspr

0

2 Answers 2

1

You can any of these formats

$user = array('user_auth' =>
    array('username' => 'will'),
    array('password' => '18218139eec55d83cf82679934e5cd75'),
    array('version' => '1.0'),
);

var_dump(serialize($user)); // use unserialize to decode
var_dump(json_encode($user)); // use json_decode to decode

You any of these formats

String user = 'a:3:{s:9:"user_auth";a:1:{s:8:"username";s:4:"will";}i:0;a:1:{s:8:"password";s:32:"18218139eec55d83cf82679934e5cd75";}i:1;a:1:{s:7:"version";s:3:"1.0";}}' (length=153)
String user = '{"user_auth":{"username":"will"},"0":{"password":"18218139eec55d83cf82679934e5cd75"},"1":{"version":"1.0"}}' (length=107)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the reply. tried both its not working!! I think I am doing something wrong!!
0

This looks like JSON (passing PHP arrays in a URL would not make much sense), but you need to use double quotes (") instead of single quotes ('), using your second example.

1 Comment

Thanks for the reply. tried that, its not working. I think I am doing something wrong!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.