2016-03-13 56 views
0

我的腳本中有錯誤,我無法找出錯誤發生的原因。已發送steamauth錯誤標題

下面是我在一個錯誤的文件:

<?php 
ob_start(); 
session_start(); 
require ('openid.php'); 

function logoutbutton() { 
    echo "<form action=\"steamauth/logout.php\" method=\"post\"><input value=\"Logout\" type=\"submit\" /></form>"; //logout button 
} 

function steamlogin() 
{ 
try { 
    require("settings.php"); 
    $openid = new LightOpenID($steamauth['domainname']); 

    $button['small'] = "small"; 
    $button['large_no'] = "large_noborder"; 
    $button['large'] = "large_border"; 
    $button = $button[$steamauth['buttonstyle']]; 

    if(!$openid->mode) { 
     if(isset($_GET['login'])) { 
      $openid->identity = 'http://steamcommunity.com/openid'; 
      header('Location: ' . $openid->authUrl()); 
     } 

    return "<form action=\"?login\" method=\"post\"> <input type=\"image\" src=\"http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_".$button.".png\"></form>"; 
    } 

    elseif($openid->mode == 'cancel') { 
     echo 'User has canceled authentication!'; 
    } else { 
     if($openid->validate()) { 
       $id = $openid->identity; 
       $ptn = "/^http:\/\/steamcommunity\.com\/openid\/id\/(7[0-9]{15,25}+)$/"; 
       preg_match($ptn, $id, $matches); 

       $_SESSION['steamid'] = $matches[1]; 
       include_once("link.php"); 
       $query = mysql_query("SELECT * FROM users WHERE steamid='".$_SESSION['steamid']."'"); 
       if (mysql_num_rows($query) == 0) 
       { 
        $time=time(); 
        mysql_query("INSERT INTO users (steamid,reg) VALUES ('".$_SESSION['steamid']."','$time')") or die("MySQL ERROR: ".mysql_error()); 
       } 
       //Determine the return to page. We substract "login&"" to remove the login var from the URL. 
       //"file.php?login&foo=bar" would become "file.php?foo=bar" 
       $returnTo = str_replace('login&', '', $_GET['openid_return_to']); 
       //If it didn't change anything, it means that there's no additionals vars, so remove the login var so that we don't get redirected to Steam over and over. 
       if($returnTo === $_GET['openid_return_to']) $returnTo = str_replace('?login', '', $_GET['openid_return_to']); 
       header('Location: '.$returnTo); 
     } else { 
       echo "User is not logged in.\n"; 
     } 

    } 
} catch(ErrorException $e) { 
    echo $e->getMessage(); 
} 
} 

?> 

的錯誤是第24行,

這一部分:

if(!$openid->mode) { 
    if(isset($_GET['login'])) { 
     $openid->identity = 'http://steamcommunity.com/openid'; 
     header('Location: ' . $openid->authUrl()); 
    } 

這是一個Steam登錄腳本,使用戶能夠登錄我的網站,我想如果有人能幫助我。

+0

可能的[如何修復]已經發送的頭「PHP中的錯誤」的副本(http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) –

回答

0

您需要推遲撥打session_start(),直到您確定的代碼塊之後。調用session_start()將HTTP標頭髮送到瀏覽器。一旦發生這種情況,您不能再使用LOCATION標題重定向到登錄頁面。