php标头无法正常工作

时间:2014-02-03 11:51:57

标签: php

我有以下功能

function redirect_to( $location = NULL ) {
  if ($location != NULL) {
   header("Location: {$location}");
    exit;
  }

然后我用它来重定向参数

$id = $photo->id; // integer 
redirect_to("photovietnam.php?id=$id");

这在我的本地系统上使用wamp工作正常。 在服务器上,正确的URL显示在头部,但似乎没有返回

有没有人有过山姆的经历?

1 个答案:

答案 0 :(得分:1)

检查文档:http://de3.php.net/manual/en/function.header.php,您可能需要拥有资源的绝对路径。

  

注意:

     

HTTP / 1.1需要绝对URI作为»Location:includes的参数   方案,主机名和绝对路径,但有些客户接受   相对URI。你通常可以使用$ _SERVER ['HTTP_HOST'],   $ _SERVER ['PHP_SELF']和dirname()从a创建一个绝对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");
exit;
?>
相关问题