Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I send a HTTP status code with typoscript?

When certain conditions meet I'd like to send the user a "403 Forbidden" HTTP status code, but I couldn't find any possibility in typoscript to modify the HTTP header. Am I missing something or is this really impossible with typoscript?

I am using Typo3 4.5.6.

like image 892
Beat Avatar asked Jun 03 '26 16:06

Beat


1 Answers

It is possible to send HTTP headers with typoscript. In your case this would be:

config.additionalHeaders = HTTP/1.0 403 Forbidden

The only problem is that the execution of any following code needs to be stopped but typoscript does not offer an exit() function or similar. So the easiest way is to use a USER_INT function:

page = PAGE

//condition
[browser = msie]
  //send HTTP 403 and exit
  includeLibs.user_httpheaders = fileadmin/templates/php/user_httpheaders.php
  page.1 = USER_INT
  page.1.userFunc = user_httpheaders->user_main
[global]

Whereas the file user_httpheaders.php contains:

<?php

    class user_httpheaders {

        public function user_main() {
            header('HTTP/1.0 403 Forbidden');
            exit;
        }

    }

?>
like image 127
vim Avatar answered Jun 05 '26 08:06

vim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!