header(“Location:mypage.php”)在上传到其他服务器后无法正常工作

In my page I used header location for redirection in twitter login. But it is working fine in my server. But it is not working after uploaded the files to other server

header("Location: login-twitter.php");

When try to see what error in the page and used the below code, I see the following warning message.

error_reporting(E_ALL); ini_set('display_errors', 'On'); 

Warning: Cannot modify header information - headers already sent by (output started at /vhosts/www/samplehosts/mysite.com/samplefolder/header.php:258) in /vhosts/www/samplehosts/mysite.com/samplefolder/signin.php on line 24

The redirection is not working on any of the pages in my site. Anybody can help me to solve this problem

signin.php

if (array_key_exists("login", $_GET)) {

    $oauth_provider = $_GET['oauth_provider'];

    if ($oauth_provider == 'twitter') {

error_reporting(E_ALL); ini_set('display_errors', 'On'); 

        header("Location: login-twitter.php");

    }

}



<li class="twitter">
<a  class="twitter_login" href="?login&oauth_provider=twitter"  rel="nofollow">
<img src="images/twitter.png" width="206" height="33" >
</a>
</li>

But after click the twitter button just it shows the header URL as

http://mysite.com/?login&oauth_provider=twitter

and not redirecting to twitter login page.

As per my understanding, your problem is that:

header("location:[XYX.PHP]") is not working.

It generally does not work due to some output is print already on the page. Please use

ob_start();

at very the beginning of the page. This starts output buffering. And the redirection works.

You can make sure your headers are always executed regardless of output by using an output buffer. Just do something like this at the top of your code:

<?php
ob_start();
// put any includes etc. here
// some other code
echo 'Sample output.';
header('Location: login-twitter.com');
// more code
ob_end_flush();
?>

In this case, because the output has been buffered, the header will still execute even though an echo statement is made before the call to header().