2014-08-27 145 views
1

我已經完全功能的網站在我的本地主機上的wamp服務器正常工作,但我上傳相同的文件到服務器上1 & 1重定向不起作用。代碼如下URL重定向問題不重定向在服務器上

<?php require_once('../model/class.user.php'); ?> 
<?php require_once('../model/class.person.php'); ?> 
<?php require_once('../model/class.session.php'); ?> 
<?php require_once('../model/class.loginrecord.php'); ?> 
<?php require_once('../controller/general_functions.php'); ?> 
<?php require_once('../controller/utility_functions.php'); ?> 

<!DOCTYPE html> 
<html lang="en"> 
<head> 

    if(isset($_POST['checkUser'])){ 



     $usrnme = htmlspecialchars($_POST['un']); 
     $paswrd = htmlspecialchars($_POST['pwd']); 

     if(!empty($usrnme) && !empty($paswrd)){ 

      //verify user credentials 
      $foundUser = User::verify(array($usrnme, $paswrd)); 


      if($foundUser){ //if user found in DB 
       //$errors[] = "Username : found<br />"; 

       $UID   = $foundUser->id; 
       $userRole  = $foundUser->role; 
       $userPersonID = $foundUser->person_id;//user_person_id has stored the reference to person's table 

       $ip = getenv('HTTP_CLIENT_IP')?: 
         getenv('HTTP_X_FORWARDED_FOR')?: 
         getenv('HTTP_X_FORWARDED')?: 
         getenv('HTTP_FORWARDED_FOR')?: 
         getenv('HTTP_FORWARDED')?: 
         getenv('REMOTE_ADDR')?: "UNKNOWN"; 

       LoginRecord::save(array(null, $foundUser->id, getCurrentDateTime(), $ip)); 

       $findPerson  = Person::findByID($userPersonID);//find the user based on the 
       $userFN   = Person::fullName($findPerson);//find the full name of the person 

       $session->setValues(md5('loginStatus'), encrypt('true')); 
       $session->setValues(md5('userID'), encrypt($UID)); 
       $session->setValues(md5('userFullName'), encrypt($userFN)); 

       if($userRole == ROLE_ADCMIN) 
       { 
        $session->setValues(md5('role'), encrypt(ROLE_ADCMIN)); 
        redirectTO('admin/dashboard.php'); 
       } 
       elseif ($userRole == ROLE_AGENT) 
       { 
        $session->setValues(md5('role'), encrypt(ROLE_AGENT)); 
        redirectTO('agent/index.php'); 
       } 
       elseif ($userRole == ROLE_OTHER) 
       { 
        redirectTO('superuser/index.php'); 
       } 

      } else { 

       $errors[] = "Sorry Username/Password not valid <br />"; 

      }//end if($foundUser) 

     } else { 

      $errors[] = "Text fields are empty."; 

     } 


    } 

重定向頁面低於功能:

function redirectTO($url = null){ 
    if($url != null){ 
     header("Location:{$url}"); 
     exit(); 
    } 
} 

我已經盡我所能,但它只是不工作顯示空白頁......可以請你幫我擺脫這個混亂......你有什麼想法嗎?

問候

+0

在本地和您的服務器上運行的php版本是什麼? – 2014-08-27 16:29:53

回答

1

使用<?php ob_start(); ?>在頁面的最開始,並在非常使用<?php ob_end_flush(); ?>頁面結尾。

1

看起來好像你正試圖重定向頁面後,你已經輸出的數據。在將任何輸出發送到瀏覽器之前,必須先發送標題。

你的HTML瀏覽:

<!DOCTYPE html> 
<html lang="en"> 
<head> 

叫你redirectTo函數之前被輸出。

此外,您在HTML之後缺少開頭的PHP標記。

+0

但是,如何在我的本地主機 – Sharif 2014-08-27 16:28:47

+0

btw沒有任何問題的情況下工作,我在哪裏輸出數據? – Sharif 2014-08-27 16:29:03

+0

我試過在PHP下的頭標記 – Sharif 2014-08-27 16:29:34

1

也許只是$url使用..不要設置$url=null

function redirectTO($url){ 
    if($url != null){ 
     header("Location:{$url}"); 
     exit(); 
    } 
} 

讓我知道,如果它的工作原理..