G'day.

I get this error when I go to some other page, or redirect to index.php
Warning: Cannot modify header information - headers already sent by (output started at /hermes/web05/blubbz/register.php on line 33

CODE on register.php:

                        <?php
                        if (isset($_POST['register_email'], $_POST['register_name'], $_POST['register_password'])) {
                            $register_email = $_POST['register_email'];
                            $register_name = $_POST['register_name'];
                            $register_password = $_POST['register_password'];

                            $errors = array();

                            if (empty($register_email) or empty ($register_name) or empty($register_password)) {
                                $errors[] = '<p style="background: #ff5e5e; border: 1px solid red; padding: 5px; font-size: 13px; color: #000;"> 
                                            <img src="" alt="" style="margin-right: 10px;" /> All fields are required! </p>';
                            }   else {

                                if (filter_var($register_email, FILTER_VALIDATE_EMAIL) === false) {
                                    $errors[] = '<p style="background: #ff5e5e; border: 1px solid red; padding: 5px; font-size: 13px; color: #000;"> 
                                                 <img src="" alt="" style="margin-right: 10px;" /> The email address is not valid! </p>';
                                }

                                if (user_exists($register_email) === true) {
                                    $errors[] = '<p style="background: #ff5e5e; border: 1px solid red; padding:5px; font-size: 13px; color: #000;"> 
                                                 <img src="" source" alt="" style="margin-right: 10px;" /> That email address is already registered! </p>';
                                }

                            }

                            if (!empty($errors)) {
                                foreach($errors as $error) {
                                    echo $error, '<br />';
                                }
                            }   else {
                                $register = user_register($register_email, $register_name, $register_password);
                                $_SESSION['user_id'] = $register;
                                header('Location: success.php');
                                exit();
                            }

                            }

                            ?>`

On line 33:

header('Location: success.php');

Any help please? Any fix for this?

Thanks

Recommended Answers

All 4 Replies

Member Avatar for diafol

look like you have some html output before this somewhere. An error can cause this or echo/print. Any HTML, including whitespace can also cause this.
Is this file an include file?

Yes, it is a include file. but I removed the include file and pasted the code in index.php too but I got the same error.

Member Avatar for diafol

Have you put it right at the top of the page before anything else? The only thing needs to go before this is the session_start().

instead of headers, you can place javascript here. replace this code section

else {
                                $register = user_register($register_email, $register_name, $register_password);
                                $_SESSION['user_id'] = $register;
                                header('Location: success.php');
                                exit();
                            }

with this one...

 else {
                                    $register = user_register($register_email, $register_name, $register_password);
                                    $_SESSION['user_id'] = $register;
                                    ?>
                                    <script type="text/javascript">
                                    window.location = "success.php";
                                    </script>
                                    <?php
                                    exit();
                                }

This truely help. Do this and let me know

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.