简体   繁体   中英

Codeigniter redirect doesn't work (blank page)

Since I have switched servers (From PHP 5 to PHP 7), I have some issues with the redirect of Codeigniter.

At the end of my code I redirect :

redirect("/contacts/afficher/$idCon", 'refresh');

But it doesn't work and it displays a blank page (with no errors). So I would like to know if someone have an explanation !

Here is my code :

<?php

$siteURL = $this->siteURL;
$accessType = $this->input->post('location');
$annee = $this->input->post('annee');
$anneeDip = $this->input->post('anneeDip');
$idDip = $this->input->post('idDip');
$reSend = $this->input->post('resend');

$contact = $this->Contacts_model->getContact($idCon);
$this->Users->createUser(null, $contact->nom, $contact->prenom, $contact->email,"contacts", $idCon, 20);
$con = "SELECT idCon,nom,prenom,con.email,username,activation_code FROM contacts AS con
JOIN ionauth_users AS u ON con.idCon=u.external_id 
WHERE con.idCon=$idCon AND u.external_type='contacts'";
$con = $this->db->query($con);
$con = $con->row();

$username = $con->username;
$pw = $this->Users->generatePassword();
$this->ion_auth->reset_password($username, $pw);

$message = "***Something***";

$object = "*****";
$title = "********************";

$this->sendMail($siteURL, $message, $object, $email, $title, null);
$this->db->set('login_sent', true);
$this->db->set('company', "");
$this->db->where('external_id', $idCon);
$this->db->where('external_type', "contacts");
$this->db->update('ionauth_users');


redirect("/contacts/afficher/$idCon", 'refresh');

Note : this code was working fine before my server migration.

Thanks

From the error you pasted above, we can understand that something is being printed before page is being rendered. Most of the times it happens because of unintentional white spaces put at the start of .php file or inside function brackets.
So, Please remove the space inside redirect() bracket like this:

redirect("/contacts/afficher", 'refresh');

If your application is not in the production server, change the environment of the application first from Application/config/config.php and set log_level to 1 . This will enable the application to display error.

If you don't want the error to be displayed, make sure you enabled error logging which will write errors to log file configured in Application/config/config.php file.

Now you should see redirection error. As explained by @PrakashG if the page renders any error/white space/HTML before redirect, redirect will not work. Make sure

  • You solve any php fatal/warning errors
  • your first character of controller / models should start with <?php and should not have any closing ?> tag on controller/model pages.
  • You can use redirect(base_url('actual/path/here')); to make sure its going to perfect place.

Let me know where you are.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM