0

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

Edited by diafol: Fixed code tags

3
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by FaisalSarfraz
0

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?

0

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.

0

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().

Edited by diafol

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.