0
I have a problem with redirecting within the builder of classe
.
Following:
I have the classe
:
<?php
class Constantes {
private $livre = false;
...
public function __construct () {
if($this->livre == false) {
header("Location: ".$_SERVER["SERVER_NAME"]."/manutencao.php");
exit;
}
.....
}
?>
Well, it is necessary that the redirection be done there in the __construct
because I have several calls to this class and change everything would be a huge job and a very difficult possible maintenance.
The redirect is being done. But it is duplicating the $_SERVER["SERVER_NAME"].
What to do?
Instead of going out to
http://www.gasmuriae.com.br/manutencao.php
It is redirecting to
http://www.gasmuriae.com.br/www.gasmuriae.com.br/manutencao.php
You can just call
$this-> minhaFuncao();
– rray
Parse error: syntax error, Unexpected '$this' (T_VARIABLE), expecting Function (T_FUNCTION) or const (T_CONST) in C: Program Files Apache24 Apache24 htdocs gasmuriae.com.br_controlls_util Constants.php on line 181
– Carlos Rocha
you created a function to redirect to another page ?
– Victor
But you call your function within another cannot get lost in the middle of the class body.
– rray
yes! exactaemnte
– Carlos Rocha
$this->minhaFuncao()
but will give error, if you want to return this use__construct()
. link Veja– user94336
I think this kind of question quite repeated in the group
– Michel Simões
Exactly, it was just making the call inside the builder. Thank you!
– Carlos Rocha
But the redirect failed. Duplicated Location:
– Carlos Rocha
tries only
header("Location: manutencao.php");
– Max Rogério
Can we? Because there are several files in different directories and subdirectories that can call the class. And this file is on the website!
– Carlos Rocha