0

这是我关于 SO 的第一个问题,我希望我做对了。我是 PHP/MySQL 编程的新手。我最近刚刚用 WAMP 建立了一个本地开发环境,它或多或少可以工作(至少,我得到了绿色图标,WAMP php 信息屏幕,phpMyAdmin 工作,我的一些 .php 文件工作正常,拉.css 和 .inc.php 来自相应目录的文件。)

我遇到问题的地方是带有 header() 的 php 重定向。

我尝试了许多不同的选项,其中一些是从这里收集的,但没有一个有效。我收到错误消息“在此服务器上找不到请求的 URL /localhost/home.php。”

此外,在浏览器的位置栏中,我得到:localhost/localhost/home.php,但我不知道为什么。

这是来自调用程序(index.php)的片段的一个版本,其中一部分是我从 SO 上的答案中得到的:

if (isset($_SESSION['Authenticated'])) {
    $host  = $_SERVER['HTTP_HOST'];
    $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    $extra = 'home.php';
    header("Location: http://$host$uri/$extra");
    exit;
    }

原始版本也不起作用,是:

if (!isset($_SESSION['Authenticated'])) {
    $redirect = 'home.php';
    header("Location: $redirect");
    exit;
    }

我还尝试了原始版本中 $redirect 变量的许多值,包括各种版本的路径,但无济于事。

就我的设置而言,这里有一些您可能会觉得有用的信息:

WAMP 服务器版本 2.2 Apache 版本 2.2.22 PHP 版本 5.4.3 MySQL 版本 5.5.24

Relevant line from C:\Windows\System32\Drivers\hosts
127.0.0.1           bke.local       #BKE Test Environment

我使用默认的 C:\wamp\www 作为 DocumentRoot

Relevant lines from C:\wamp\bin\apache\apache2.2.22\conf\httpd.conf:
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "c:/wamp/www/"
.
.
.
# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf


Relevant lines from C:\wamp\bin\apache\apache2.2.22\conf\extra\httpd.vhosts.conf:
# Use name-based virtual hosting.
NameVirtualHost *:80
#####NameVirtualHost 127.0.0.1:80
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "c:/apache2/docs/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "logs/dummy-host.example.com-error.log"
    CustomLog "logs/dummy-host.example.com-access.log" common
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "c:/apache2/docs/dummy-host2.example.com"
    ServerName dummy-host2.example.com
    ErrorLog "logs/dummy-host2.example.com-error.log"
    CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

#<Directory C:/Dev>
#   Order Deny,Allow
#   Allow from all
#</Directory>

我的文件的当前位置: .php 文件到 C:\wamp\www .css 文件到 C:\wamp\www\styles .inc.php 文件到 C:\wamp\www\includes

在我意识到我遇到了这个问题之前,我尝试使用来自多个网站的信息(所有网站都说同样的事情)设置多个虚拟主机,但根本无法做到这一点,所以我取消了我的更改并去了使用 WAMP 默认值。我怀疑这些问题是相关的,但无法解决其中任何一个问题。

4

1 回答 1

0

我要在这里冒险了。

在我更详细地研究之前,我相信这是一个简单的疏忽。

你试一试:

if (!isset($_SESSION['Authenticated']))
{
  header ("Location: home.php");
  exit;
} // this will basically re-direct to home.php if $_SESSION['Authenticated'] is not set

但在执行上面发布的代码段之前,只需执行以下操作:

echo "http://$host$uri/$extra";

没有 header(); 只是看看这是否是问题所在。

于 2013-04-04T01:54:48.397 回答