Reputation: 139
I am a novice and I work in PHP. My English is not very good. If you see a typo, please edit it.
I need a function that changes the status of the site. Like the following function:
var_dump(http_response_code()); // return 200
function changeStatus($from, $to) {
// The code I need
}
changeStatus(200, 404);
var_dump(http_response_code()); // return 404
Is such a thing possible at all? please guide me
Upvotes: 1
Views: 112
Reputation: 685
This is wrong because it returns the previous result
var_dump(http_response_code(404)); // return 200
Try this. This answer is safer
function changeStatus($responseCode)
{
if (http_response_code($responseCode))
return true;
else
return false;
}
changeStatus(404);
Upvotes: 1
Reputation: 182
This code will solve your problem
function changeStatus($response_code) {
// The code I need
http_response_code($response_code);
}
changeStatus(404);
var_dump(http_response_code());
Upvotes: 3