Send http-404 response BUT dont send custom error page setted in IIS server | PHP -
lets understand scenario:
:- using php web application on iis 8.5
:- custom error page set 404 following web-config snippt:
<httperrors errormode="custom" existingresponse="replace"> <remove statuscode="404" substatuscode="-1" /> <error statuscode="404" path="/path/404.php" responsemode="executeurl" /> </httperrors>
:- working non-existing page and iis also return 404.php if set header 404 (via header('http/1.0 404 not found', true, 404); die;
) in php page.
question:
now, wan send 404 http response code in php-file on specific condition, lets if database returns 0 rows. can setting header above return custom error page also. is there way send 404 code , tell iis send response is, without sending custom error page along it?
issues:
:- if remove custom error page , put content between header()
, die()
meet requirement iis fail serve custom error on pages doesn't exist.
:- using url rewrite cannot use multiple custom error pages based on location
tag , don't want redirect suggested different urls.
as have 1 tricky solution/idea, want share also. if have better solution, welcome , them.
trick/solution/idea:
step 1:- existing php-page set
session variable
beforeheader('http/1.0 404 not found', true, 404);
, put specific message in variable(i suggest use different integer code session variable's value different php-pages) set header , calldie(); or exit;
.step 2:- after iis or other server execute custom error page. so, in custom error page check session variable , echo content follows....
........2a - if session variable not set display "normal error content main menu" etc.
........2b - if session variable set check value , according value display different content want show user like: "data not found message , search panel"
note: in custom error page's coding again need set 404 header, , can send different error code according session variable's value in above trick.
Comments
Post a Comment