# Problem with change header location

**URL:** https://discourse.roots.io/t/problem-with-change-header-location/20830
**Category:** sage
**Created:** 2021-05-24T13:17:20Z
**Posts:** 5

## Post 1 by @grzesiek1owline — 2021-05-24T13:17:20Z

OS: Linux Ubuntu 20.04  
Sage 10

Hi, I’m trying to create my own login form via facebook and google. I am using the SocialConnect library.  
Here are my files:

```
// resources/views/form-register.blade.php
        <form action="{{ REGISTER_PAGE }}" method="POST">
            <button type="submit" name="provider" value="google">google</button>
            <button type="submit" name="provider" value="fb">fb</button>
        </form>
```

And the file where I want to handle the event

```
// app/View/Composers/Register.php

<?php

namespace App\View\Composers;

use SocialConnect\Auth\Service;
use SocialConnect\HttpClient\Curl;
use SocialConnect\HttpClient\RequestFactory;
use SocialConnect\HttpClient\StreamFactory;
use SocialConnect\Common\HttpStack;
use SocialConnect\Provider\Session\Session;

class Register extends Composer
{

    public function __construct()
    {
        // COMMON
        $this->is_logged = false;
        $this->error = false;

        // GOOGLE API INFO
        $this->google_id = '100725804944-o108tp4vdcrellsd0lrfpnl59kdq4j54.apps.googleusercontent.com';
        $this->google_secret = 'GlnL98Xxhi9TlYzrUFdX-Yxi';
        $this->google_redirect = REGISTER_PAGE;
        $this->google_loggin_url = false;

        // FACEBOOK
        $this->fb_api = '320462216157040';
        $this->fb_secret = '879143dacd27e105ed711abd0755e242';
        $this->fb_login_url = false;

        $this->auth = false;
    }

    protected static $views = [
        'register',
    ];

    public function with()
    {
        return [
            'logged' => $this->is_logged,
            'error' => $this->error,
            'auth' => $this->SocialAuth(),

        ];
    }

    public function SocialAuth(){
 
        if(!isset($_POST['provider'])) {
            return false;
        }

        $httpClient = new Curl();
        $httpStack = new HttpStack(
            $httpClient,
            new RequestFactory(),
            new StreamFactory()
        );

        $collectionFactory = null;

        $configureProviders = [
            'redirectUri' => REGISTER_PAGE,
            'provider' => [
                'facebook' => [
                    'applicationId' => '',
                    'applicationSecret' => '',
                    'scope' => ['email'],
                    'options' => [
                        'identity.fields' => [
                            'email',
                            'picture.width(99999)'
                        ],
                    ],
                ],
                'google' => [
                    'applicationId' => $this->google_id,
                    'applicationSecret' => $this->google_secret,
                ],
            ],
        ];

        $service = new Service(
            $httpStack,
            new Session(),
            $configureProviders,
            $collectionFactory
        );

        $providerName = $_POST['provider'];
        $provider = $service->getProvider($providerName);
        write_log($provider->makeAuthUrl());
        header('Location: ' . $provider->makeAuthUrl());
        exit;
    }

}
```

This class is not complete but i have a problem on this stage. After selecting the login method, the following error appears:

```
Cannot modify header information - headers already sent by (output started at /home/owline/Local Sites/talenti/app/public/wp-includes/class.wp-scripts.php:237)
```

I have no idea if it’s my code or sage problem.

---

## Post 2 by @strarsis — 2021-05-24T15:33:36Z

> [@grzesiek1owline](#):
>
> `class.wp-scripts.php:237`

The warning indicates that the PHP script already send some body data - which would cause the HTTP headers to be send with no way of later changing them on that request. What happens on that line `class.wp-scripts.php:237`, is something printed or included or an error caused?

---

## Post 3 by @grzesiek1owline — 2021-05-24T15:43:49Z

Hm, wp-scripts is default wp-includes file.

> <https://github.com/WordPress/WordPress/blob/master/wp-includes/class.wp-scripts.php>

---

## Post 4 by @strarsis — 2021-05-24T16:23:34Z

This seems to be a classic issue with UTF-8 BOM. WordPress loads a theme template file that contains a BOM which causes PHP to send it as body - together with the HTTP response headers that can’t be changed anymore afterwards.

---

## Post 5 by @alwaysblank — 2021-05-24T17:28:05Z

> [@grzesiek1owline](#):
>
> `header('Location: ' . $provider->makeAuthUrl());`

You’re attempting to modify headers inside of a Composer, which you can’t do. By the time a Composer is being executed, the headers for whatever page you’re on have already been sent (in this case by wp-scripts, apparently). If you need to conditionally modify headers, you’ll need to hook into a action like [`wp_headers`](https://developer.wordpress.org/reference/hooks/wp_headers/) or [`send_headers`](https://developer.wordpress.org/reference/hooks/send_headers/), and do it outside of a Composer. Composers are meant for _modifying data and passing it to views_, not for containing redirect functionality, which appears to be what you’re trying to do here.

---

## Post 6 by @system — 2021-07-05T13:17:20Z

This topic was automatically closed after 42 days. New replies are no longer allowed.
