简体   繁体   中英

The function “header” does not work

I have a problem with that header. When the page is processed I will only exit();

if($validate=='true') {
        $_SESSION['nome'] = $nome;
        $_SESSION['cognome'] = $cognome;
        $_SESSION['email'] = $email;
        $_SESSION['telefono'] = $telefono;
        $_SESSION['cellulare'] = $cellulare;
        $_SESSION['password'] = $password;
        $_SESSION['societa'] = $societa;
        $_SESSION['pi'] = $pi;
        $_SESSION['cf'] = $tax;
        $controllor = md5(uniqid(rand(), TRUE));

        ob_start();
             header("Location: index.php?nav=8&controllor=".$controllor);
        ob_end_flush();
        exit();


    }

All variables above are filled correctly and $validate is equal to 'true'.

Location header should use absolute uri.

http://php.net/manual/en/function.header.php

Anyway check if you have already sent the headers:

http://www.php.net/manual/en/function.headers-sent.php

Also you have no need to use ob_start or ob_end in this case.

Firstly, using output buffering to avoid writing proper code should be avoided; it could potentially have saved you from this.

Secondly, the way you are using output buffering to avoid header error messages, is wrong. Output buffering should be started as the first thing.

With no error messages or more code to work out your problem, an obvious suggestion would be to remove the output buffering, move the functionality with the header function() to a point before any output to the browser is made.

Since your $validate equals true. I suggest this solution , Otherwise i won't

You could replace your header() with this Javascript.

echo "<script>location.href=index.php?nav=8&controllor='$controllor'</script>";

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