0

I'm trying to implement a simple login system in my application. The C# application would send a POST request with user id and password to the PHP script. Then the PHP script would check if the user id exists, and if the password is correct. If yes, it would return some data(time left, unique id). I'm not sure how to return the data to my application though, what would be the best way in your opinion?

Thanks.

2 Answers 2

1

Just echoing it in the response body as usual would be the most obvious option. If it's more complex data, you could use a standard like json_encode() that you can parse in C#.

Example:

$data["time_left"] = 12023932103129;
$data["unique_id"] = 203032924420;

echo json_encode($data);  // will output a JSON string that you can decode
                          // in C#.

Additionally, you could consider using status codes for error handling, for example:

if ($error)
 {
   header("HTTP/1.1 500 Internal Server Error");
   echo "Details of the error in here";
 }
Sign up to request clarification or add additional context in comments.

Comments

1

echo it in the response as an xml-document, so let php build a valid xml document. C# is particularly good in parsing xml.

string xml = /* get your xml document from php */
var xDocument = XDocument.Parse(xml);

http://msdn.microsoft.com/en-us/library/bb345532.aspx

Comments

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.