L
L
lexstile2017-02-17 18:22:06
CMS
lexstile, 2017-02-17 18:22:06

How to solve the header problem?

You need to give the code in the 404 header instead of 200.
ba12e9d21d164b9b8fc9968ea7e7b424.JPG
The code that should set the 404 is:

if($this->group_id == -1)
    {
      //header("HTTP/1.1 404 Not Found", true, 404);
      header("HTTP/1.1 404 Not Found");
      ToolkitLib::ShowError("Ошибка. Выбрана несуществующая группа.");
      return false;
    }

Now the code is sent in headers 200, it cannot be redefined, I wanted to php.net/manual/ru/function.http-response-code.php
I can't catch it either, I didn't find it in the file.
Menu.class.php file:
pastecode.ru/1c389f
PHP version: 5.2
HostCMS: 5.9

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2017-02-17
@lexstile

The header can only be changed if you haven't started uploading data yet.
Solutions to the problem:

  1. Find in your CMS the ability to display all content once, and in such modules only prepare content. Then you can use the header function there.
  2. Redirect to 404 page on error using JS. Something like this (keep your code style):
    <?php
    ...
    if($this->group_id == -1) { ?>
          <script> window.alert('Ошибка. Выбрана несуществующая группа'); windows.location.replace('/404'); </script>
    <?php }

    PS PHP 5.2. Seriously?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question