Problem redirecting from the controller

2

When registering a user I send and receive from the model in the following function:

$respuesta=Datos::RegistroUsuarioModel($datosusuarios,"usuarios");

    if($respuesta == "success"){
        header("location.index.php?action=ok");
            }
            else{
                header("location:index.php");
            }

when registering the user successfully enters success, but sends me the following error:

  

Warning: Can not modify header information - headers already sent by   (output started at   C: \ xampp \ htdocs \ coffee \ controller \ controller.php: 63) in   C: \ xampp \ htdocs \ coffee \ controller \ controller.php on line 121

this is my line 63:

echo '<option value="'.$item['id_pais'].'">'.$item['PaisNombre'].'</option>';

and this is line 121:

header("location.index.php?action=ok");

I have already read in all the forums about the problem and I have not been able to solve it

    
asked by jorgnv 17.08.2017 в 19:26
source

1 answer

2

The notice of

  

Warning: Can not modify header information - headers already sent by (output started at C: \ xampp \ htdocs \ coffee \ controller \ controller.php: 63) in C: \ xampp \ htdocs \ coffee \ controller \ controller.php online 121

It comes to you because you are sending extra information or changing the information that is sent in the headers of the HTTP response when you have already sent previous content information. In the very specific case of your code, it's because you're sending html tags on that line 63 and then you're sending new headers at:

header("location.index.php?action=ok");

Check why you are printing that echo of line 63 of the controller.php file on the screen,

Also the header that you are sending is badly written, when you try to change a header as a general rule you should write the variable with the first letter of each word with a capital letter if there are more words in the variable separated with "-" and To separate the variable from the value, use a ":" sign followed by a space. When trying to change the Location variable, you must put the variable with the entire URL including the protocol, in the following way:

header("Location: http://localhost/index.php?action=ok");

You can see the header documentation in link

As an additional tip to get the name of the server you are using you can get it with $ _SERVER ['HTTP_HOST']

    
answered by 03.04.2018 в 04:32