mordad
mordad

Reputation: 139

How can I change the status of the site? - PHP

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

Answers (2)

mehmet
mehmet

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

Virender Kumar
Virender Kumar

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

Related Questions