2013-10-30 77 views
-1

我的php代码不工作时,我上传server.when我在localhost上运行它的工作fine..why ??php代码doesent工作时上传到服务器

<?php 
ob_start(); 
include 'CUserDB.php'; 
session_start(); 
include 'config.php'; 
$myusername=$_POST['txtusername']; 
$mypassword=$_POST['txtpassword']; 
$typ= $_POST['type']; 
$myusername = stripslashes($myusername); 
$mypassword = stripslashes($mypassword); 
$typ = stripslashes($typ);  
$myusername = mysql_real_escape_string($myusername); 
$mypassword=mysql_real_escape_string($mypassword); 
$typ = mysql_real_escape_string($typ);   
     try { 
      $oUser = new CUserDB(); 
      $result = $oUser->Login($myusername,$mypassword,$typ); 
      } 
     catch (PDOException $pe) 
     { 
      die("Error occurred:" . $pe->getMessage()); 
     } 
    if($result[0][0][UserName] != '') 
     { 
      session_start(); 
      $_SESSION['UserId'] = $myusername; 
      if($typ == "Dealer") 
      { 
      header('location:Dealer/ManageProfile.php'); 
      } 
      else if ($typ == "Individual") 
      { 
      header('location:Individual/managep.php'); 
      } 
      else 
      { 
      header('location:Builder/managep.php'); 
      } 
     } 
    else 
    { 
    header('location:header.php'); 
    } 
?> 

这是checklogin页当我在server.after点击登录此网页越做越服务器called.but它doesent后停留checklogin.php页面上登录页面重定向运行此。为什么这在服务器上发生?

+0

错误日志中是否有任何内容?可能是'header already'错误... – Konsole

+0

*服务器上发生了什么* PHP代码是否由服务器解释? (或者你在渲染的页面源中看到它?)PHP日志中是否有错误? Web服务器记录?如果您添加一些额外的调试和日志记录到代码中,它在哪里以及如何失败? – David

+0

我为什么被投票?我甚至不能问问题? – dvirus

回答

2

Location头,根据http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html,应该是一个绝对URI,例如:

Location: http://yourserver/header.php 

此外,适当的标题名称是Location,大写。
空格字符也应该出现在冒号字符和标题值之间。

根据PHP文档:

通常可以使用$ _ SERVER [ 'HTTP_HOST'],$ _ SERVER [ 'PHP_SELF']和目录名()从相对一个自己做的绝对URI:现在

<?php 
/* Redirect to a different page in the current directory that was requested */ 
$host = $_SERVER['HTTP_HOST']; 
$uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); 
$extra = 'mypage.php'; 
header("Location: http://$host$uri/$extra"); 

,我不能肯定地说,你写了他们的重定向将不会工作,有可能是另外一个问题,但你应该尽量尊重HTTP协议尽可能以避免兼容性问题。

+0

仍然不能正常工作 – dvirus

+0

因此,您应该在您的问题中提供更多详细信息,因为这在代码中看起来有些不对。必须有一个你看不到的错误。尝试使用XDebug和与之协同工作的IDE来调试代码,这将对您有很大帮助。 – SirDarius

1
  1. 检查您的代码没有任何语法错误。像http://phpcodechecker.com/应该可以正常工作。
  2. 仔细检查包含的文件是否包含在内。尝试将它们改为需要,看看会发生什么
  3. 确保PDO扩展存在并正常工作。快速执行phpinfo()并查看启用了哪些内容。
  4. 启用错误(如果他们还没有)并按照他们的方式工作。
相关问题