I have an error that is generated now that I have the web page uploaded in host
, but when I was working in localhost
, the page worked normally
Warning: session_start(): Cannot start session when headers already sent in /storage/ssd2/242/10438242/public_html/Jomar/users_control/controller/ControlAsisController.php on line 12
To contextualize, I have several controllers, one of them is where I do the respective login, this controller is AdminController
, so I do a session_start()
in the constructor of AdminController
and in the login method I already create the variable, taking this into account, because in it it AdminController
works with normally, session
but when I go to another page that calls another controller, in this case ControlAsisController
it throws me the error, but I have done the session_start()
in the constructor of that too, so I don't understand what is happening, if someone can help me help, I appreciate it, I hope it is understandable.
I attach the part of the code where I do thesession_start()
AdminController.php
class AdminController{
public function __construct(){
$action = isset($_GET["action"]) ? $_GET["action"] : "todos";
session_start();
if($action == "enviarCorreoMail" || $action == "enviarCorreo" || $action == "generarCodigo"){
$this->login();
}else{
if(method_exists($this, $action)){
$this->$action();
}else{
$this->error();
}
}
}
ControlAsisController.php
class ControlAsisController{
public function __construct(){
$action = isset($_GET["action"]) ? $_GET["action"] : "todos";
session_start();
if(!isset($_SESSION["login"]) || !$_SESSION["login"]){
include '../views/administrador/login.php';
return;
}
if(method_exists($this, $action)){
$this->$action();
}else{
$this->error();
}
}
It is very likely that you are printing some content before you call:
Try to place it at the beginning of the execution.