How return http_code 401 with PHP

I'm using cUrl in the client side.

On my webservice (ws.php), i've this simple code :

header('HTTP/1.1 401 Unauthorized', true, 401);
echo 'This is an error';

When i call this ws.php page, i still have http_code = 200.

Here is my cUrl code is client side :

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "webservice_url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_variables); //array()

$response = curl_exec($ch);
$code = curl_getinfo($ch,CURLINFO_HTTP_CODE);


$code = 200 even i put the header code "401".


try this on your ws.php:

header('HTTP/1.0 401 Unauthorized');
echo 'This is an error';

Let me know if this works or not ?

Need Your Help

How to set caption for youtube videos box in css?

html css

I have created youtube videos after click an image.

Where to put ApplicaitonSettings in a layered mvc project?


I've got a basic MVC project that has a Web project, a Service dll project and a Data dll project. I started to store config values in the web project's applicaiton settings but I've come a...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.