How to make so that at a certain if was a server error?

Are the following:
There is an Android application which upon registration is on the server, PHP processes the data, and should return a negative response, but if all the rules that entered into database.
How to make let's say if a user of the application enters a name (say): "hi", then PHP gave a server error? That is, I need to study to in Android could get, they say the server doesn't like your name, select more.
I was thinking something like this:
if($_POST['username'] == 'hi') http_response_code(500);

or so
if($_POST['username'] == 'hi') header($_SERVER['SERVER_PROTOCOL'] . '500 Internal Server Error', true, 500);

But not the same =( And even better to do in this situation, that on Android I could get an error which gives a server?
June 14th 19 at 18:24
3 answers
June 14th 19 at 18:26
throw new Exception()
Nifiga, gives 200..
if($_POST['username'] == 'hi') throw new Exception('Error'); - eloisa32 commented on June 14th 19 at 18:29
if($_POST['username'] == 'hi') throw new Exception('Error', 500);
- esther.Roh commented on June 14th 19 at 18:32
even so, this result
200, OK
date: Sun, 08 Oct 2017 20:24:19 GMT
x-content-type-options: nosniff
server: awex
- eloisa32 commented on June 14th 19 at 18:35
IF ever work for you?
do if($_POST['username'] == 'hi') return 'This is the IF!'; - esther.Roh commented on June 14th 19 at 18:38
it worked, my blunt was, thank you - eloisa32 commented on June 14th 19 at 18:41
Not for that - esther.Roh commented on June 14th 19 at 18:44
another question, all these answers they are the same (I mean, like a 500 error)
And perhaps we can make Android the answer came supposedly if nick is "hi" then "hi Nick the impossible", and if repeated, the nickname "Is the name we have in the database". Just if I am a "error 500" and try to give, it can be interpreted in different ways. - eloisa32 commented on June 14th 19 at 18:47
Write different IF-s:
if($_POST['username'] == 'hi') throw new Exception('hi Nick impossible', 500);

if (check for existence in DB) throw new Exception('That name we have in the database', 500);
- esther.Roh commented on June 14th 19 at 18:50
June 14th 19 at 18:28
What kind of perverted? Why would the server not responding properly "I don't like your name" with code 200?
Yes, and the criteria for "good/bad name" is pretty vague. This regular season still need to write....
Well so I'm at the end asked for help "how to do?"
It is better to give json_encode()? - eloisa32 commented on June 14th 19 at 18:31
Yes to give even json, though the raw string, but with a code 200 (code 200 will be spent immediately). Ie on the server, you specify a valid name or not (e.g. using regular expressions) and depending on this, send the client either "Registration successful" or "Invalid name".
Importantly, the message from the error is generated not by the server, and your code. - esther.Roh commented on June 14th 19 at 18:34
well so if the message is using echo, as in Android I get this information?
If json_encode a let down then at least rospars json and get. No? - eloisa32 commented on June 14th 19 at 18:37
the same as everything else. This application parses any html when it receives a response from the server. - esther.Roh commented on June 14th 19 at 18:40
June 14th 19 at 18:30
With the 500 error bad option. All HTTP errors introduced for technical problems, not for problems with biznesowych. In your case, the server is working fine, so it is necessary to return 200. Better modify biznesowych.

Find more questions by tags PHP