Piero Vignola
Piero Vignola

Reputation: 11

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'.

Upvotes: 0

Views: 383

Answers (3)

Repox
Repox

Reputation: 15475

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.

Upvotes: 1

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>";

Upvotes: 0

Loksly
Loksly

Reputation: 124

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.

Upvotes: 1

Related Questions