How to send HTTP response code?

0 votes
I have a PHP script that needs to make responses with HTTP response codes (status-codes), like HTTP 200 OK, or some 4XX or 5XX code.

How can I do this in PHP?
Sep 14 in PHP by kartik
• 30,630 points
24 views

1 answer to this question.

0 votes

Hello @kartik,

you can use http_response_code() for get and set header status code.

here an example:

<?php

// Get the current response code and set a new one
var_dump(http_response_code(404));

// Get the new response code
var_dump(http_response_code());
?>

Hope it helps!!

Thank YoU!!

answered Sep 14 by Niroj
• 66,420 points

Related Questions In PHP

0 votes
0 answers
0 votes
1 answer

How to configure XAMPP to send mail from localhost?

Hello @kartik, You can send mail from localhost ...READ MORE

answered Sep 13 in PHP by Niroj
• 66,420 points
56 views
0 votes
2 answers

How to make asynchronous HTTP requests in PHP?

file_get_contents will do what you want $output = ...READ MORE

answered Sep 22 in PHP by Rajiv
• 140 points
21 views
0 votes
1 answer

How to execute PHP code from the command line?

Hello @kartik, the php command offers two switches to ...READ MORE

answered Oct 1 in PHP by Niroj
• 66,420 points
33 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 66,420 points
2,699 views
0 votes
1 answer

What is type casting and type juggling in php?

Hey, The way by which PHP can assign ...READ MORE

answered Mar 27 in PHP by Niroj
• 66,420 points
440 views
0 votes
1 answer

How can we create a session in PHP?

Hello @kartik, session_start() function is used in PHP to ...READ MORE

answered Mar 27 in PHP by Niroj
• 66,420 points
84 views
0 votes
1 answer

What is the use of $_REQUEST variable in php?

Hii @kartik, The $_REQUEST variable is used to read the ...READ MORE

answered Mar 27 in PHP by Niroj
• 66,420 points
130 views
0 votes
1 answer

How to send email using php?

Hello @kartik 1.) Download PHPMailer, open the zip file ...READ MORE

answered Apr 1 in PHP by Niroj
• 66,420 points
94 views
0 votes
1 answer

How to convert PHP code to MySQL query to CSV?

Hello @kartik, Try this: SELECT * INTO OUTFILE "c:/mydata.csv" FIELDS ...READ MORE

answered Aug 20 in PHP by Niroj
• 66,420 points
39 views