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.
在我的页面中,我使用标题位置在twitter登录中进行重定向。 但它在我的服务器上工作正常。 但是将文件上传到其他服务器 p>
当试图查看页面中的错误并使用下面的代码时,我看到以下警告信息。 p>
警告:无法修改标头信息 - 已经发送的标头(在/vhosts/www/samplehosts/mysite.com/samplefolder/header.php上输出
started: 258)在第24行的
/ vhosts / www / samplehosts / mysite.com / samplefolder / signin.php p>
重定向不适用于我站点中的任何页面。 任何人都可以帮我解决这个问题 p>
signin.php strong> p>
但点击推特按钮后,只显示标题网址为 p>
http://mysite.com/?login&oauth_provider=twitter p>
而不是重定向到Twitter登录页面。 p>
div> header(“Location:login-twitter.php”); code> p>
\ n
error_reporting(E_ALL); ini_set('display_errors','On');
code> pre>
if(array_key_exists(“login”) ,$ _GET)){
$ oauth_provider = $ _GET ['oauth_provider'];
if($ oauth_provider =='twitter'){
error_reporting(E_ALL); ini_set('display_errors','On');
标题(“位置:login-twitter.php”);
}
}
&lt; li class =“twitter”&gt;
&lt; a class = “twitter_login”href =“?login&amp; oauth_provider = twitter”rel =“nofollow”&gt;
&lt; img src =“images / twitter.png”width =“206”height =“33”&gt;
&lt; / a&gt; ;
&lt; / li&gt;
code> pre>
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().