Featured post
drupal 6 - PHP: Get http status code that own script just sent out via shutdown function -
i have shutdown function checks see if redirect issued. headers_list() can headers sent , see location header. question how figure out http_response_code used in header() function. headers list doesn't have response code.
example code play around with. don't use redirects in example code, otherwise loop. main thing detect 301 vs other kind of redirect. inside drupal (via drupal_goto using hook_exit); example code below shows issue. have no way of knowing status number passed browser via header().
<?php register_shutdown_function('test'); if (mt_rand(0, 1)) { header('x-test: junk 1', true, 201); } else { header('x-test: junk 0', true, 202); } exit(); function test() { if ($location = test_headers_contain('x-test: ')) { // check status code sent out echo $location . '<br>'; $list = headers_list(); $txt = str_replace(' ', ' ', nl2br(htmlentities(print_r($list, true)))); echo $txt; } } function test_headers_contain($text) { if (function_exists('headers_list')) { $list = headers_list(); if (empty($list)) { return false; } foreach ($list $header) { $info = stristr($header, $text); if ($info !== false) { return $info; } } } return false; } ?>
this code outputs this
x-test: junk 1 array ( [0] => x-powered-by: php/5.2.10 [1] => x-test: junk 1 )
revision 302033 added function http_response_code
in response sort of issue describe, i'm not when included in release. it's not in 5.3.4. if have access, build patched version of php function added. if not, request of whoever on host have access.
- Get link
- X
- Other Apps
Comments
Post a Comment