0

I´ve read through about 10 similiar questions as mine, but couldn´t find a solution.

I created a simple forum based website on my students-domain on which it worked finde. I also created a webserver with my raspberry pi on which it also worked like a charme.

But know I moved to a public domain with the same php-version but now I keep running into this error:

Cannot modify header information - headers already sent by (output started at /home/site/public_html/forum/config.inc.php:1) in /home/site/public_html/forum/action_login.php on line 9

I checked whitespaces, tried with exit(header(Location: "X")); or header(Location: "X");exit; and also used absolute pathes.

But nothing worked.

This is the file I´m getting stuck in:

<?php
    session_start();
    error_reporting(E_ALL & ~E_NOTICE);
    require_once('config.inc.php');
    $host = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);


    if(((empty($_POST['username'])) || (empty($_POST['password']))) && (isset($_POST['Login'])))
    { 
        header("Location: $host/index.php?error=2");exit;
    }


    else if(!preg_match("/^[a-zA-Z0-9äöüÄÖÜ-]*$/", $_POST['username']) && isset($_POST['Login']))
    {
        header("Location: $host/index.php?error=1");exit;
    }


    else
    {
        $logedin = $auth->login($_POST['username'], $_POST['password']);
        $userId = $auth->getUserID($_POST['username']);


        if($logedin)
        {
            $_SESSION['name'] = strtolower($_POST['username']);
            $_SESSION['id'] = $userId;
        }

        header("Location: $host/startpage.php");exit;
    }


    if(isset($_POST['Logout']))
    {
        session_destroy();

        header("Location: $host/index.php");exit;
    }

So I submit the credentials from my login.php and then get stuck in my action_login.php, because the header() won´t redirect me.

Thanks for your help

Qirel
  • 25,449
  • 7
  • 45
  • 62
  • Check your `config.inc.php` file, it states the output starts there, on the first line. Might be a whitespace or something. – Qirel Mar 22 '17 at 17:40
  • session_start() is causing the problem i think. Like OP said, html is outputted before starting sessions. it cant be! check your require files for html outputs – pbu Mar 22 '17 at 17:44
  • Make sure there is nothing before `` in the config.inc.php file. Many leave out the `?>` completely, otherwise it is too easy to put accidental whitespace after it such as a carriage return. – Octopus Mar 22 '17 at 17:46

0 Answers0