1

preg_match を使用して「401 Access Denied」をチェックしようとしています。出力できるように正しい情報を取得できないようです。

HTTP/1.1 401 Access Denied Set-Cookie: cprelogin=no; 
HttpOnly; path=/; port=2082 Set-Cookie: 
cpsession=%3aXYBHer1OXxaqzCNVLHNR3ujtmdkZow6PYsnyE8daVUF1lq8fQBiFd7EeHJ99CK93; 
HttpOnly; path=/; port=2082 Server: cpsrvd/11.34.1.4 Content-type: text/html;
4

1 に答える 1

2

のようなものを試してください

preg_match('#^HTTP\/1\.(0|1)\s401#i', $yourheaders, $match);

if(!empty($match) && !is_null($match[1])){
   echo "failed";
}else{
   echo "ok";
}

得た:

  HTTP/1.1 500 Internal Server Error Set-Cookie: cprelogin=no;.
  HttpOnly; path=/; port=2082 Set-Cookie:.
  cpsession=%3aXYBHer1OXxaqzCNVLHNR3ujtmdkZow6PYsnyE8daVUF1lq8fQBiFd7EeHJ99CK93;.
  HttpOnly; path=/; port=2082 Server: cpsrvd/11.34.1.4 Content-type: text/html;

ok
Array
(
)

401:

HTTP/1.1 401 Access Denied Set-Cookie: cprelogin=no; 
HttpOnly; path=/; port=2082 Set-Cookie: 
cpsession=%3aXYBHer1OXxaqzCNVLHNR3ujtmdkZow6PYsnyE8daVUF1lq8fQBiFd7EeHJ99CK93; 
HttpOnly; path=/; port=2082 Server: cpsrvd/11.34.1.4 Content-type: text/html;

failed
Array
(
    [0] => HTTP/1.1 401
    [1] => 1
)
于 2012-12-08T15:44:59.290 に答える